Documentation
¶
Index ¶
- Variables
- func MakePermRecord(perm PermInfo) entity.Permission
- func MakePermRecordList(perms []PermInfo) (ens []entity.Permission)
- func MakeRolePerms(roleId uint, permIds []uint) []entity.RolePermission
- func MakeRoleRecord(info RoleInfo) entity.Role
- func MakeRoleRecordList(infos []RoleInfo) (records []entity.Role)
- func MakeUserRoleRecordList(userId uint, roleIds []uint) []entity.UserRole
- type CreatePermOption
- type CreateRoleOption
- type GrantOption
- type PageOption
- type PermGroup
- type PermInfo
- type QueryRolePermsOption
- type RoleInfo
- type UpdatePermOption
- type UpdateRoleOption
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrRoleNotFound = errs.NewI18nError("role.notfound").FallBack("role not found").Code(code.ResourceNotFound) ErrRoleConflict = errs.NewI18nError("role.conflict").FallBack("role already exists") ErrInvalidRoles = errs.NewI18nError("role.invalidList").FallBack("invalid roles") )
View Source
var ( ErrPermNotFound = errs.NewI18nError("perm.notfound").FallBack("permission not found").Code(code.ResourceNotFound) ErrPermConflict = errs.NewI18nError("perm.conflict").FallBack("permission already exists") ErrPermNoAccess = errs.NewI18nError("perm.noPerm").FallBack("no enough permission to access") ErrInvalidPerm = errs.NewI18nError("perm.invalidPerm").FallBack("invalid permissions") )
View Source
var ( RulePermObj = helper.Rules(vax.Match(PermObjectRule.Regx).Code(PermObjectRule.I18n), vax.RangeLenRune(1, 200)) RulePermAct = helper.Rules(vax.RangeLenRune(1, 60), is.Alpha) RulePermTag = helper.Rules(vax.RangeLenRune(1, 20), is.Alphanumeric) RulePermGroup = helper.Rules(vax.RangeLenRune(1, 60)) RuleRoleName = helper.Rules(vax.RangeLenRune(1, 60)) RuleRoleCode = helper.Rules(vax.RangeLenRune(1, 30), is.Alphanumeric) )
View Source
var ( // AdminRole app static admin role, AdminRole = RoleInfo{ Name: "Admin", Code: "1024", } UserRole = RoleInfo{ Name: "User", Code: "0512", } AnonymousRole = RoleInfo{ Name: "Guest", Code: "0000", } )
View Source
var (
PermObjectRule = helper.RegexRule{Regx: regexp.MustCompilePOSIX("^[a-zA-Z0-9/_-]*$"), I18n: "rule.perm.object"}
)
Functions ¶
func MakePermRecord ¶
func MakePermRecord(perm PermInfo) entity.Permission
func MakePermRecordList ¶
func MakePermRecordList(perms []PermInfo) (ens []entity.Permission)
func MakeRolePerms ¶
func MakeRolePerms(roleId uint, permIds []uint) []entity.RolePermission
func MakeRoleRecord ¶
func MakeRoleRecordList ¶
Types ¶
type CreatePermOption ¶
type CreatePermOption struct { Name string `json:"name" label:"field.perm.name" example:"updateUser"` // define the object will be accessed Object string `json:"object" label:"field.perm.object" example:"/user/update"` // how to access the object Action string `json:"action" label:"field.perm.action" example:"POST"` // permission group Group string `json:"group" label:"field.perm.group" example:"UserGroup"` // tag of permission Tag string `json:"tag" label:"field.perm.tag" example:"AppAPI"` }
func (CreatePermOption) Validate ¶
func (c CreatePermOption) Validate(lang string) error
type CreateRoleOption ¶
type CreateRoleOption struct { // role name Name string `json:"name" label:"field.role.name" example:"admin"` // role code, must be alpha numeric Code string `json:"code" label:"field.role.code" example:"ADMIN"` }
func (CreateRoleOption) Validate ¶
func (c CreateRoleOption) Validate(lang string) error
type GrantOption ¶
type GrantOption struct { RoleId uint `json:"roleId" label:"field.role.id" example:"1"` Tag string `json:"tag" label:"field.role.tag" example:"AppApi"` PermIds []uint `json:"permId" label:"field.perm.list"` }
func (GrantOption) Validate ¶
func (g GrantOption) Validate(lang string) error
type PageOption ¶
type PageOption struct { helper.PageOption Search string `json:"search" uri:"search" form:"search" example:"admin"` Tag string `json:"tag" uri:"tag" form:"tag" example:"appapi"` }
type PermGroup ¶
type PermGroup struct { // group name Group string `json:"group" example:"user group"` Perms []PermInfo `json:"perms"` }
func MakePermGroup ¶
func MakePermGroup(perms []entity.Permission) []PermGroup
type PermInfo ¶
type PermInfo struct { // permission id Id uint `json:"id" example:"1"` // permission name Name string `json:"name" example:"updateUser"` // define the object will be accessed Object string `json:"object" example:"/user/update"` // permission group Group string `json:"group" example:"admin"` // how to access the object Action string `json:"action" example:"POST"` // tag of permissions Tag string `json:"tag" example:"AppAPI"` }
func MakePermInfo ¶
func MakePermInfo(perm entity.Permission) PermInfo
func MakePermInfoList ¶
func MakePermInfoList(perms []entity.Permission) (infos []PermInfo)
type QueryRolePermsOption ¶
type QueryRolePermsOption struct { system.Id Tag string `json:"tag" uri:"tag" form:"tag" label:"field.perm.tag" example:"AppAPI"` }
func (QueryRolePermsOption) Validate ¶
func (q QueryRolePermsOption) Validate(lang string) error
type RoleInfo ¶
type RoleInfo struct { // role id Id uint `json:"id" example:"1"` // role name Name string `json:"name" example:"admin"` // role code, must be alpha numeric Code string `json:"code" example:"ADMIN"` }
func MakeRoleInfo ¶
func MakeRoleInfoList ¶
type UpdatePermOption ¶
type UpdatePermOption struct { Id uint `json:"id" example:"1"` Name string `json:"name" label:"field.perm.name" example:"updateUser"` }
func (UpdatePermOption) Validate ¶
func (u UpdatePermOption) Validate(lang string) error
type UpdateRoleOption ¶
type UpdateRoleOption struct { Id uint `json:"id" example:"1"` // role name Name string `json:"name" label:"field.role.name" example:"admin"` }
func (UpdateRoleOption) Validate ¶
func (u UpdateRoleOption) Validate(lang string) error
Click to show internal directories.
Click to hide internal directories.