role

package
v0.0.0-...-b400081 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2021 License: CC0-1.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRoleManagerNonUnique    = errors.New("Role manager name must be unique")
	ErrRoleNameNonUnique       = errors.New("Role name must be unique")
	ErrPermissionNameNonUnique = errors.New("Permission name must be unique")

	ErrRoleNotExists = errors.New("Role does not exist")

	// ErrRoleManagerNotExists occurs only when in json manager name is not valid
	ErrRoleManagerNotExists = errors.New("Role manager does not exist")
)
View Source
var (
	ErrNilPermission = errors.New("Nil permission pointer was passeed")
)

Functions

This section is empty.

Types

type Permission

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

type Role

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

func (*Role) Allow

func (r *Role) Allow(permissions ...*Permission)

Allow a permission to the role. Allow panics if any of permissions is nil.

func (*Role) Disallow

func (r *Role) Disallow(permissions ...*Permission)

Disallow the specific permission. Disallow panics if any of permissions is nil.

func (*Role) IsAllowedTo

func (r *Role) IsAllowedTo(p *Permission) bool

IsAllowedTo returns true if the role has specific permission. IsAllowedTo panics if p is nil.

func (*Role) MarshalJSON

func (r *Role) MarshalJSON() ([]byte, error)

MarshalJSON implements Marshaler interface.

func (*Role) UnmarshalJSON

func (r *Role) UnmarshalJSON(data []byte) error

UnmarshalJSON implements Unmarshaler interface.

type RoleManager

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

func MustNewManager

func MustNewManager(name string) *RoleManager

MustNewManager is the same as NewManager, accept it panics is name is non unique.

func NewManager

func NewManager(name string) (*RoleManager, error)

NewManager creates new permission, name must be alway unique. NewManager return error if name is non unique.

func (*RoleManager) MustNewPermission

func (rm *RoleManager) MustNewPermission(name string) *Permission

MustNewPermission is the same as NewPermission, accept it panics is name is non unique.

func (*RoleManager) MustNewRole

func (rm *RoleManager) MustNewRole(name string, permissions ...*Permission) *Role

MustNewRole is the same as NewRole, accept it panics is name is non unique.

func (*RoleManager) NewPermission

func (rm *RoleManager) NewPermission(name string) (*Permission, error)

NewPermission creates new permission, name must be unique across one RoleManager. NewPermission return error if name is non unique.

func (*RoleManager) NewRole

func (rm *RoleManager) NewRole(name string, permissions ...*Permission) (*Role, error)

NewRole creates new role, name must be unique across one RoleManager. NewRole return error if name is non unique.

Jump to

Keyboard shortcuts

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