This repository has been archived on 2024-02-27. You can view files and clone it, but cannot push or open issues or pull requests.
arf/types/permission.go

49 lines
808 B
Go
Raw Normal View History

2022-08-10 10:52:20 -06:00
package types
type Mode int
const (
ModeNone = iota
ModeRead
2022-08-10 10:52:20 -06:00
ModeWrite
)
type Permission struct {
Internal Mode
External Mode
}
func ModeFrom (char rune) (mode Mode) {
switch (char) {
2022-08-11 02:52:16 -06:00
case 'n': mode = ModeNone
case 'r': mode = ModeRead
case 'w': mode = ModeWrite
}
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
}
func (permission Permission) ToString () (output string) {
output += permission.Internal.ToString()
output += permission.External.ToString()
return
}