// // access.go // Copyright (C) 2024 veypi // 2024-09-23 19:37 // Distributed under terms of the MIT license. // package auth import "github.com/golang-jwt/jwt/v5" type AuthLevel uint const ( DoNone = 0 Do = 1 DoRead = 1 DoCreate = 2 DoUpdate = 3 DoDelete = 4 DoAll = 5 ) type Access []*struct { Name string `json:"name"` TID string `json:"tid"` Level AuthLevel `json:"level"` } func (a *Access) Check(target string, tid string, l AuthLevel) bool { if l == DoNone { return true } for _, line := range *a { if target == line.Name && l >= line.Level { if line.TID == "" || line.TID == tid { return true } } } return false } type Claims struct { UID string `json:"uid"` AID string `json:"aid"` Name string `json:"name"` Icon string `json:"icon"` Access Access `json:"access"` jwt.RegisteredClaims }