Files
proxy/server/web/auth/context.go

42 lines
798 B
Go
Raw Normal View History

2025-02-19 14:23:58 +08:00
package auth
type Context interface {
Permissions() map[string]struct{}
PermitAll(permissions ...string) bool
PermitAny(permissions ...string) bool
}
// region DeviceContext
type DeviceContext struct {
ID uint
IpAddress string
Permissions map[string]struct{}
}
func (c DeviceContext) PermitAny(permissions ...string) bool {
if _, exist := c.Permissions["*"]; exist {
return true
}
for _, permission := range permissions {
if _, ok := c.Permissions[permission]; ok {
return true
}
}
return false
}
func (c DeviceContext) PermitAll(permissions ...string) bool {
if _, exist := c.Permissions["*"]; exist {
return true
}
for _, permission := range permissions {
if _, ok := c.Permissions[permission]; !ok {
return false
}
}
return true
}
// endregion