grim/hgkeeper

closing merged branch
access-control
2019-05-07, Gary Kramlich
e92e1e8ee230
closing merged branch
package access
// A Perm represents one or more access permissions: reading, writing, etc.
type Perm uint32
// All permisions constants
const (
Init Perm = 1 << iota
Read
Write
numPerms = 3
)
// String returns a textual representation of the perm.
func (p Perm) String() string {
var r string
if p.can(Init) {
r += "init|"
}
if p.can(Read) {
r += "read|"
}
if p.can(Write) {
r += "write|"
}
if len(r) == 0 {
return "none"
}
return r[:len(r)-1]
}
func (p *Perm) can(i Perm) bool { return *p&i != 0 }
func (p *Perm) clear(i Perm) { *p &^= i }
func (p *Perm) set(i Perm) { *p |= i }