2022-03-28 13:00:26 +02:00
|
|
|
//go:build go1.18
|
2022-05-24 00:44:36 +02:00
|
|
|
// +build go1.18
|
2022-03-28 13:00:26 +02:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
type AccessRole uint16
|
|
|
|
|
|
|
|
func (r AccessRole) Is(v AccessRole) bool {
|
|
|
|
return r&v != 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r AccessRole) Allow(v AccessRole) bool {
|
|
|
|
return r&v >= v
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
InvalidAccessRole AccessRole = 1 << iota
|
|
|
|
Read
|
|
|
|
Write
|
|
|
|
Delete
|
|
|
|
|
|
|
|
Owner = Read | Write | Delete
|
|
|
|
Member = Read | Write
|
|
|
|
)
|
|
|
|
|
|
|
|
type User struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
Role AccessRole `json:"role"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u User) GetID() string {
|
|
|
|
return u.ID
|
|
|
|
}
|