Documentation ¶
Index ¶
- Constants
- Variables
- func HasRole(req *http.Request, user interface{}, roles ...string) bool
- func MatchedRoles(req *http.Request, user interface{}) []string
- func Register(name string, fc Checker)
- func Remove(name string)
- func Reset()
- type Checker
- type Permission
- func (permission *Permission) Allow(mode PermissionMode, roles ...string) *Permission
- func (permission *Permission) Concat(newPermission *Permission) *Permission
- func (permission *Permission) Deny(mode PermissionMode, roles ...string) *Permission
- func (permission Permission) HasPermission(mode PermissionMode, roles ...interface{}) bool
- type PermissionMode
- type Permissioner
- type Role
- func (role *Role) Allow(mode PermissionMode, roles ...string) *Permission
- func (role *Role) Deny(mode PermissionMode, roles ...string) *Permission
- func (role *Role) Get(name string) (Checker, bool)
- func (role *Role) HasRole(req *http.Request, user interface{}, roles ...string) bool
- func (role *Role) MatchedRoles(req *http.Request, user interface{}) (roles []string)
- func (role *Role) NewPermission() *Permission
- func (role *Role) Register(name string, fc Checker)
- func (role *Role) Remove(name string)
- func (role *Role) Reset()
- type Roler
Constants ¶
const (
// Anyone is a role for any one
Anyone = "*"
)
Variables ¶
var ErrPermissionDenied = errors.New("permission denied")
ErrPermissionDenied no permission error
var Global = &Role{}
Global global role instance
Functions ¶
func MatchedRoles ¶
MatchedRoles return defined roles from user
Types ¶
type Permission ¶
type Permission struct { Role *Role AllowedRoles map[PermissionMode][]string DeniedRoles map[PermissionMode][]string }
Permission a struct contains permission definitions
func Allow ¶
func Allow(mode PermissionMode, roles ...string) *Permission
Allow allows permission mode for roles
func Deny ¶
func Deny(mode PermissionMode, roles ...string) *Permission
Deny deny permission mode for roles
func NewPermission ¶
func NewPermission() *Permission
NewPermission initialize a new permission for default role
func (*Permission) Allow ¶
func (permission *Permission) Allow(mode PermissionMode, roles ...string) *Permission
Allow allows permission mode for roles
func (*Permission) Concat ¶
func (permission *Permission) Concat(newPermission *Permission) *Permission
Concat concat two permissions into a new one
func (*Permission) Deny ¶
func (permission *Permission) Deny(mode PermissionMode, roles ...string) *Permission
Deny deny permission mode for roles
func (Permission) HasPermission ¶
func (permission Permission) HasPermission(mode PermissionMode, roles ...interface{}) bool
HasPermission check roles has permission for mode or not
type PermissionMode ¶
type PermissionMode string
PermissionMode permission mode
const ( // Create predefined permission mode, create permission Create PermissionMode = "create" // Read predefined permission mode, read permission Read PermissionMode = "read" // Update predefined permission mode, update permission Update PermissionMode = "update" // Delete predefined permission mode, deleted permission Delete PermissionMode = "delete" // CRUD predefined permission mode, create+read+update+delete permission CRUD PermissionMode = "crud" )
type Permissioner ¶
type Permissioner interface {
HasPermission(mode PermissionMode, roles ...interface{}) bool
}
Permissioner permissioner interface
func ConcatPermissioner ¶
func ConcatPermissioner(ps ...Permissioner) Permissioner
ConcatPermissioner concat permissioner
type Role ¶
type Role struct {
// contains filtered or unexported fields
}
Role is a struct contains all roles definitions
func (*Role) Allow ¶
func (role *Role) Allow(mode PermissionMode, roles ...string) *Permission
Allow allows permission mode for roles
func (*Role) Deny ¶
func (role *Role) Deny(mode PermissionMode, roles ...string) *Permission
Deny deny permission mode for roles
func (*Role) MatchedRoles ¶
MatchedRoles return defined roles from user
func (*Role) NewPermission ¶
func (role *Role) NewPermission() *Permission
NewPermission initialize permission