Changed permission codes to only determine private/public/readonly
Changing permissions within the module was redundant and would have just conflicted with the :mut type qualifier. This is easier to understand.pull/6/head
parent
15eb96e8ac
commit
a548dcc585
@ -1,48 +1,63 @@
|
||||
package types
|
||||
|
||||
type Mode int
|
||||
type Permission int
|
||||
|
||||
const (
|
||||
ModeNone = iota
|
||||
ModeRead
|
||||
ModeWrite
|
||||
// Displays as: pv
|
||||
//
|
||||
// Other modules cannot access the section or member.
|
||||
PermissionPrivate Permission = iota
|
||||
|
||||
// Displays as: ro
|
||||
//
|
||||
// Other modules can access the section or member, but can only read its
|
||||
// value. It is effectively immutable.
|
||||
//
|
||||
// Data sections, member variables, etc: The value can be read by other
|
||||
// modules but not altered by them
|
||||
//
|
||||
// Functions: The function can be called by other modules.
|
||||
//
|
||||
// Methods: The method can be called by other modules, but cannot be
|
||||
// overriden by a type defined in another module inheriting from this
|
||||
// method's reciever.
|
||||
PermissionReadOnly
|
||||
|
||||
// Displays as: rw
|
||||
//
|
||||
// Other modules cannot only access the section or member's value, but
|
||||
// can alter it. It is effectively mutable.
|
||||
//
|
||||
// Data sections, member variables, etc: The value can be read and
|
||||
// altered at will by other modules.
|
||||
//
|
||||
// Functions: This permission cannot be applied to non-method functions.
|
||||
//
|
||||
// Methods: The method can be called by other modules, and overridden by
|
||||
// types defined in other modules inheriting from the method's reciever.
|
||||
PermissionReadWrite
|
||||
)
|
||||
|
||||
type Permission struct {
|
||||
Internal Mode
|
||||
External Mode
|
||||
}
|
||||
|
||||
func ModeFrom (char rune) (mode Mode) {
|
||||
switch (char) {
|
||||
case 'n': mode = ModeNone
|
||||
case 'r': mode = ModeRead
|
||||
case 'w': mode = ModeWrite
|
||||
// PermissionFrom creates a new permission value from the specified text. If the
|
||||
// input text was not valid, the function returns false for worked. Otherwise,
|
||||
// it returns true.
|
||||
func PermissionFrom (data string) (permission Permission, worked bool) {
|
||||
worked = true
|
||||
switch data {
|
||||
case "pv": permission = PermissionPrivate
|
||||
case "ro": permission = PermissionReadOnly
|
||||
case "rw": permission = PermissionReadWrite
|
||||
default: worked = false
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func PermissionFrom (data string) (permission Permission) {
|
||||
if len(data) != 2 { return }
|
||||
|
||||
permission.Internal = ModeFrom(rune(data[0]))
|
||||
permission.External = ModeFrom(rune(data[1]))
|
||||
return
|
||||
}
|
||||
|
||||
func (mode Mode) ToString () (output string) {
|
||||
switch mode {
|
||||
case ModeNone: output = "n"
|
||||
case ModeRead: output = "r"
|
||||
case ModeWrite: output = "w"
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// ToString converts the permission value into a string.
|
||||
func (permission Permission) ToString () (output string) {
|
||||
output += permission.Internal.ToString()
|
||||
output += permission.External.ToString()
|
||||
switch permission {
|
||||
case PermissionPrivate: output = "pv"
|
||||
case PermissionReadOnly: output = "ro"
|
||||
case PermissionReadWrite: output = "rw"
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue