1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-11-22 19:33:27 +01:00
This commit is contained in:
binwiederhier 2023-01-02 22:28:43 -05:00
parent 21c33f1e82
commit 2f725bf80d

View file

@ -109,6 +109,7 @@ const (
PermissionReadWrite // 3! PermissionReadWrite // 3!
) )
// NewPermission is a helper to create a Permission based on read/write bool values
func NewPermission(read, write bool) Permission { func NewPermission(read, write bool) Permission {
p := uint8(0) p := uint8(0)
if read { if read {
@ -120,6 +121,7 @@ func NewPermission(read, write bool) Permission {
return Permission(p) return Permission(p)
} }
// ParsePermission parses the string representation and returns a Permission
func ParsePermission(s string) (Permission, error) { func ParsePermission(s string) (Permission, error) {
switch s { switch s {
case "read-write", "rw": case "read-write", "rw":
@ -135,18 +137,22 @@ func ParsePermission(s string) (Permission, error) {
} }
} }
// IsRead returns true if readable
func (p Permission) IsRead() bool { func (p Permission) IsRead() bool {
return p&PermissionRead != 0 return p&PermissionRead != 0
} }
// IsWrite returns true if writable
func (p Permission) IsWrite() bool { func (p Permission) IsWrite() bool {
return p&PermissionWrite != 0 return p&PermissionWrite != 0
} }
// IsReadWrite returns true if readable and writable
func (p Permission) IsReadWrite() bool { func (p Permission) IsReadWrite() bool {
return p.IsRead() && p.IsWrite() return p.IsRead() && p.IsWrite()
} }
// String returns a string representation of the permission
func (p Permission) String() string { func (p Permission) String() string {
if p.IsReadWrite() { if p.IsReadWrite() {
return "read-write" return "read-write"