Documentation ¶
Index ¶
Constants ¶
View Source
const ( PrefixUserID = "u" PrefixRoleID = "r" UserIDCtxName = "casbinUserId" SuperUserID = 1 )
Variables ¶
View Source
var ( ErrUidEmpty = errors.New("uid not found") ErrCasbin = errors.New("auth model exception") )
Functions ¶
func CheckPermission ¶
func CheckPermission() gin.HandlerFunc
CheckPermission 根据不同的错误返回不同的 http code - 未找到用户,403 - casbin 报错,500 - 没有权限,401
func GormAdapter ¶
func GormAdapter(dbConf mysql.Options) (*gormadapter.Adapter, error)
Types ¶
type Casbiner ¶
type Casbiner interface { RedisWatcher(channel string) error CheckPermissionForUser(userId int64, permission ...any) (bool, error) AddPermissionForRole(roleId int64, permission ...string) error AddPermissionsForRole(roleId int64, permission ...[]string) error DeletePermissionForRole(roleId int64, permission ...string) error DeleteRole(roleIds []int64) error DeleteUser(userIds []int64) error AddRoleForUser(userId int64, roleIds []int64) error DeleteRoleForUser(userId int64, roleIds []int64) error DeleteRolesForUser(userId int64) error Enforcer() *casbin.Enforcer }
Click to show internal directories.
Click to hide internal directories.