Documentation ¶
Index ¶
- func BindPrincipal(ctx context.Context, principal Principal) (context.Context, error)
- func HasPermWithPrinciapl(ctx context.Context, principal Principal) bool
- func HasPermWithPrincipalAndPerms(principal Principal, reqPerms []*Perm) bool
- func ReqPerm(ctx context.Context, perms []*Perm) (context.Context, error)
- type Operation
- type Perm
- type Principal
- type Resource
- type ResourceGroup
- type ResourceRegistry
- type Role
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindPrincipal ¶
BindPrincipal 在ctx中绑定principal
func HasPermWithPrinciapl ¶
HasPermWithPrinciapl 检查principal是否拥有ctx中要求的权限
func HasPermWithPrincipalAndPerms ¶
HasPermWithPrincipalAndPerms 检查principal是否拥有reqPerms指定的权限
Types ¶
type Operation ¶
type Operation int8
Operation 定义操作类型
type Principal ¶
type Principal interface { // GetID 取得principal的id GetID() int64 // GetName 取得principal的名称 GetName() string // GetRoles 取得principal所拥有的角色 GetRoles() []Role }
Principal 定义了拥有权限的主体
type Resource ¶
type Resource struct {
// contains filtered or unexported fields
}
Resource 定义资源
func NewResource ¶
NewResource 创建一个新的资源
func NewResourceAndReg ¶
func NewResourceAndReg(registry *ResourceRegistry, name, id string, parent *Resource) *Resource
NewResourceAndReg 创建并新建一个资源,如果相同的资源在registry中已经存在,则会panic
type ResourceGroup ¶
ResourceGroup 资源分组
type ResourceRegistry ¶
type ResourceRegistry struct {
// contains filtered or unexported fields
}
ResourceRegistry 记录所有的资源
func (*ResourceRegistry) Add ¶
func (p *ResourceRegistry) Add(resource *Resource) error
Add 注册一个Resource,如果相同的资源在registry中已经存在,返回error
func (*ResourceRegistry) BuildResourceGroup ¶
func (p *ResourceRegistry) BuildResourceGroup(depth int) (groups []*ResourceGroup, err error)
BuildResourceGroup 构建resource group列表
func (*ResourceRegistry) IsExist ¶
func (p *ResourceRegistry) IsExist(resID string) bool
IsExist 检查指定的资源id是否存在
Click to show internal directories.
Click to hide internal directories.