erbac

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRoleExist    = errors.New("角色已经存在")
	ErrRoleNotExist = errors.New("角色不存在")
	ErrFounfdCircle = errors.New("发现环继承")
	Empty           = struct{}{}
)

Functions

func AllGranted

func AllGranted(rbac *RBAC, roles []string, permission Permission,
	assert AssertionFunc) (r bool)

func AnyGranted

func AnyGranted(rbac *RBAC, roles []string, permission Permission,
	assert AssertionFunc) (r bool)

func BuildRBAC

func BuildRBAC(roleFile, inherFile string) (*RBAC, Permissions, error)

从文件中构建erbac

func InherCircle

func InherCircle(rbac *RBAC) (err error)

func LoadJson

func LoadJson(filename string, v interface{}) error

func SaveJson

func SaveJson(filename string, v interface{}) error

func Walk

func Walk(rbac *RBAC, h WalkHandler) (err error)

Types

type AssertionFunc

type AssertionFunc func(*RBAC, string, Permission) bool

type Permission

type Permission interface {
	ID() string
	Match(Permission) bool
}

func NewStdPermission

func NewStdPermission(id string) Permission

type Permissions

type Permissions map[string]Permission

type RBAC

type RBAC struct {
	// contains filtered or unexported fields
}

func NewRBAC

func NewRBAC() *RBAC

func (*RBAC) Add

func (rbac *RBAC) Add(r Role) (err error)

给当前的rbac添加一个拥有权限的角色

func (*RBAC) Get

func (rbac *RBAC) Get(id string) (r Role, parents []string, err error)

func (*RBAC) GetParents

func (rbac *RBAC) GetParents(id string) (parents []string, err error)

func (*RBAC) IsGranted

func (rbac *RBAC) IsGranted(id string, p Permission, assert AssertionFunc) (res bool)

func (*RBAC) Remove

func (rbac *RBAC) Remove(id string) (err error)

移除一个角色

func (*RBAC) RemoveParent

func (rbac *RBAC) RemoveParent(id string, parent string) error

移除单个parent

func (*RBAC) SaveUserRBAC

func (rbac *RBAC) SaveUserRBAC(newRoleFile, newInherFile string) error

func (*RBAC) SaveUserRBACWithSort added in v1.0.1

func (rbac *RBAC) SaveUserRBACWithSort(newRoleFile, newInherFile string) error

func (*RBAC) SetParent

func (rbac *RBAC) SetParent(id string, parent string) error

设置单个parent

func (*RBAC) SetParents

func (rbac *RBAC) SetParents(id string, parents []string) error

设置多个parent

type Role

type Role interface {
	ID() string
	Permit(Permission) bool
}

Role is an interface.

type Roles

type Roles map[string]Role

Roles is a map

type StdPermission

type StdPermission struct {
	IDStr string
}

func (*StdPermission) ID

func (sp *StdPermission) ID() string

func (*StdPermission) Match

func (sp *StdPermission) Match(p Permission) bool

type StdRole

type StdRole struct {
	sync.RWMutex
	IDStr string `json:"id"`
	// contains filtered or unexported fields
}

func NewStdRole

func NewStdRole(id string) *StdRole

func (*StdRole) Assign

func (role *StdRole) Assign(p Permission) error

Assign 分配权限

func (*StdRole) ID

func (role *StdRole) ID() string

ID returns the role's identity name.

func (*StdRole) Permissions

func (role *StdRole) Permissions() []Permission

展开stdRole的Permissions

func (*StdRole) Permit

func (role *StdRole) Permit(p Permission) (rslt bool)

Permit 进行权限判断

type WalkHandler

type WalkHandler func(Role, []string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL