api.spaceplanner.app

Spaceplanner API
git clone git://jacobedwards.org/api.spaceplanner.app
Log | Files | Refs

permissions.go (703B)


      1 package backend
      2 
      3 /*
      4  * In the future this will hold something like this
      5  *
      6  * type Permission {
      7  *	Name string
      8  *	Allowed bool
      9  * }
     10  * 
     11  * for whatever permissions might need to be enforced, such as
     12  * service levels.
     13  */
     14 
     15 type unsignedNumeric interface {
     16 	uint8 | uint16 | uint32 | uint64 | uint
     17 }
     18 
     19 var (
     20 	NoAccess AccessPermission = 0
     21 	ReadAccess AccessPermission = 1
     22 	WriteAccess AccessPermission = 2
     23 )
     24 
     25 type AccessPermission uint8
     26 
     27 func (p AccessPermission) Read() bool {
     28 	return (p & ReadAccess) != 0
     29 }
     30 
     31 func (p AccessPermission) Write() bool {
     32 	return (p & WriteAccess) != 0
     33 }
     34 
     35 func setBit(mask uint8, bit uint8, set bool) uint8 {
     36 	if set {
     37 		return mask | bit
     38 	} else {
     39 		return mask & ^bit
     40 	}
     41 }