Documentation ¶
Index ¶
- Constants
- Variables
- type Group
- func (group *Group) AddPermission(permission *Permission)
- func (group *Group) GetName() string
- func (group *Group) GetPermissions() map[string]*Permission
- func (group *Group) HasPermission(permission string) bool
- func (group *Group) InheritGroup(inheritedGroup *Group)
- func (group *Group) RemovePermission(permission string)
- type Manager
- func (manager *Manager) AddGroup(group *Group)
- func (manager *Manager) GetDefaultGroup() *Group
- func (manager *Manager) GetGroup(name string) (*Group, error)
- func (manager *Manager) GetPermission(name string) (*Permission, error)
- func (manager *Manager) GroupExists(name string) bool
- func (manager *Manager) IsPermissionRegistered(name string) bool
- func (manager *Manager) RegisterPermission(permission *Permission)
- func (manager *Manager) RemoveGroup(name string)
- func (manager *Manager) SetDefaultGroup(group *Group)
- type Permissible
- type Permission
- func (permission *Permission) AddChild(child *Permission)
- func (permission *Permission) GetChildren() map[string]*Permission
- func (permission *Permission) GetDefaultLevel() int
- func (permission *Permission) GetName() string
- func (permission *Permission) HasChild(name string) bool
- func (permission *Permission) SetDefaultLevel(level int)
- type PermissionLevel
Constants ¶
const ( LevelVisitor PermissionLevel = iota LevelMember = 1 LevelOperator = 2 LevelCustom = 3 )
Variables ¶
var ( UnknownPermission = errors.New("unknown permission") UnknownGroup = errors.New("unknown group") )
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group is a struct used for basic permission managing. Groups can be granted a set of permissions.
func (*Group) AddPermission ¶
func (group *Group) AddPermission(permission *Permission)
AddPermission adds a permission to the group.
func (*Group) GetPermissions ¶
func (group *Group) GetPermissions() map[string]*Permission
GetPermissions returns a name => permission map of all permissions of the group.
func (*Group) HasPermission ¶
HasPermission checks if the group has a permission with the name.
func (*Group) InheritGroup ¶
InheritGroup inherits all permissions from a group.
func (*Group) RemovePermission ¶
RemovePermission removes a permission with the given name from the group.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is a struct used to manage permissions and groups. It provides helper functions and functions to register groups and permissions.
func (*Manager) GetDefaultGroup ¶
GetDefaultGroup returns the default group of the manager.
func (*Manager) GetGroup ¶
GetGroup returns a group in the manager with the given name and an error if it could not be found.
func (*Manager) GetPermission ¶
func (manager *Manager) GetPermission(name string) (*Permission, error)
GetPermission returns a permission by its name, and an error if it could not be found.
func (*Manager) GroupExists ¶
GroupExists checks if a group with the given name exists.
func (*Manager) IsPermissionRegistered ¶
IsPermissionRegistered checks if a permission with the given name is registered.
func (*Manager) RegisterPermission ¶
func (manager *Manager) RegisterPermission(permission *Permission)
RegisterPermission registers a new permission.
func (*Manager) RemoveGroup ¶
RemoveGroup removes a group with the given name from the manager.
func (*Manager) SetDefaultGroup ¶
SetDefaultGroup sets the default group of the manager.
type Permissible ¶
type Permissible interface { HasPermission(string) bool RemovePermission(string) AddPermission(*Permission) }
Permissible is an interface used to satisfy for permission holders.
type Permission ¶
type Permission struct {
// contains filtered or unexported fields
}
Permission is a struct with a name, a default level and children. Every child permission can in turn have its own child permissions.
func NewPermission ¶
func NewPermission(name string, defaultLevel int) *Permission
NewPermission returns a new permission with the given name and default level.
func (*Permission) AddChild ¶
func (permission *Permission) AddChild(child *Permission)
AddChild adds the given permission as child permission.
func (*Permission) GetChildren ¶
func (permission *Permission) GetChildren() map[string]*Permission
GetChildren returns a name => permission child permission map of all children.
func (*Permission) GetDefaultLevel ¶
func (permission *Permission) GetDefaultLevel() int
GetDefaultLevel returns the default level of required to be granted the permission.
func (*Permission) GetName ¶
func (permission *Permission) GetName() string
GetName returns the name of the permission.
func (*Permission) HasChild ¶
func (permission *Permission) HasChild(name string) bool
HasChild checks if the permission has a child with the given name.
func (*Permission) SetDefaultLevel ¶
func (permission *Permission) SetDefaultLevel(level int)
SetDefaultLevel sets the default level of the the permission.
type PermissionLevel ¶
type PermissionLevel byte
A Permission level is used to connect groups with permissions.