init commit

This commit is contained in:
2025-02-19 14:23:58 +08:00
commit 10a4f010ce
34 changed files with 1340 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
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