Documentation
¶
Index ¶
- Constants
- Variables
- func InitPermission(source interface{}, tx ...*gorm.DB)
- type ExcludeFunc
- type Model
- type OptionsFunc
- type PageComponent
- type Permission
- func (p *Permission) Auth(role, path, method string) (bool, error)
- func (p *Permission) GetUserPermission(ctx context.Context, id int64) (*UPermissionExtend, error)
- func (p *Permission) LoadPolicy() error
- func (p *Permission) Middleware(userKey ...string) gin.HandlerFunc
- func (p *Permission) WithOptions(opts OptionsFunc)
- type SysApi
- type SysMenu
- type SysMenuApi
- type SysRole
- type SysRoleMenu
- type SysRule
- type UPermission
- type UPermissionExtend
Constants ¶
View Source
const ( MenuTypeDirectory uint8 = iota + 1 // 目录 MenuTypePage // 页面 MenuTypeButton // 页面中的按钮 MenuTypeTab // 页面里的tab页 )
菜单类型
View Source
const ( CheckLevelNone uint8 = iota // 目录/页面不展示 CheckLevelHalf // 目录/页面部分展示 CheckLevelAll // 目录/页面全部展示 )
View Source
const ( EffectNormal uint8 = iota + 1 // 按钮正常 EffectHidden // 按钮隐藏 EffectDisabled // 按钮禁用 )
View Source
const ( RoleKeySysAdmin = "sys_admin" RoleKeySysSecurity = "sys_security" RoleKeySysAudit = "sys_audit" RoleKeySysOperator = "sys_operator" )
View Source
const ( TableRule = "sys_rule" TableRole = "sys_role" TableApi = "sys_api" TableMenu = "sys_menu" TableRoleMenu = "sys_role_menu" TableMenuApi = "sys_menu_api" )
Variables ¶
View Source
var ErrorJWTPermission = errors.New("permission denied")
Functions ¶
func InitPermission ¶
InitPermission 初始化 casbin
Types ¶
type OptionsFunc ¶
type PageComponent ¶
type PageComponent struct {
Code string `json:"name"` // 按钮唯一标识
Description string `json:"description"` // 按钮描述
Parent *UPermission `json:"-"`
Effect uint8 `json:"effect"` // 按钮权限 1:正常显示 2:隐藏 3:禁用
}
type Permission ¶
type Permission struct {
// contains filtered or unexported fields
}
var Auth *Permission
func (*Permission) Auth ¶
func (p *Permission) Auth(role, path, method string) (bool, error)
Auth 单次鉴权
func (*Permission) GetUserPermission ¶
func (p *Permission) GetUserPermission( ctx context.Context, id int64, ) (*UPermissionExtend, error)
GetUserPermission 获取用户菜单信息
func (*Permission) Middleware ¶
func (p *Permission) Middleware(userKey ...string) gin.HandlerFunc
Middleware 中间件
func (*Permission) WithOptions ¶
func (p *Permission) WithOptions(opts OptionsFunc)
type SysApi ¶
type SysMenu ¶
type SysMenuApi ¶
type SysMenuApi struct {
Model
MenuCode string `gorm:"column:menu_code"`
ApiID int64 `gorm:"column:api_id"`
}
func (*SysMenuApi) TableName ¶
func (s *SysMenuApi) TableName() string
type SysRole ¶
type SysRoleMenu ¶
type SysRoleMenu struct {
Model
RoleID int64 `gorm:"column:role_id"`
MenuCode string `gorm:"column:menu_code"`
}
func (*SysRoleMenu) TableName ¶
func (s *SysRoleMenu) TableName() string
type SysRule ¶
type UPermission ¶
type UPermission struct {
ID int64 `json:"-"`
Code string `json:"routerName"` // 前端菜单唯一表示
Title string `json:"title"` // 菜单名称
CheckLevel uint8 `json:"checkLevel"` // 0:未选 1:部分选择 2:全选
Parent *UPermission `json:"-"`
Children []*UPermission `json:"children"` // 子菜单
Component []*PageComponent `json:"pageApis"` // 某个菜单下属按钮、tab页面
}
UPermission 用户权限
func AssembleMenuToTree ¶
func AssembleMenuToTree(ctx context.Context, menuAll []*SysMenu, menuMap map[string]*UPermission) []*UPermission
AssembleMenuToTree 将平级的menu组装成树形 menuAll 菜单全量记录列表 menuMap 存放id到permission指针映射,方便子节点插入
type UPermissionExtend ¶
type UPermissionExtend struct {
CheckedKeys []string `json:"checked_keys"`
HalfCheckedKeys []string `json:"half_checked_keys"`
PermissionMap []*UPermission `json:"permission_map"`
}
Click to show internal directories.
Click to hide internal directories.