authorization

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Authorizer

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

Authorizer manages roles, permissions, and policies

func New

func New() *Authorizer

New creates a new Authorizer

func (*Authorizer) AllowPolicy

func (a *Authorizer) AllowPolicy(action string, fn PolicyFunc)

AllowPolicy registers a policy function for an action

func (*Authorizer) Can

func (a *Authorizer) Can(user *core.User, action string, resource interface{}) bool

Can checks if a user can perform an action on a resource using policies

func (*Authorizer) DefineRole

func (a *Authorizer) DefineRole(role string, permissions ...string)

DefineRole defines a role with a set of permissions

func (*Authorizer) GetRolePermissions

func (a *Authorizer) GetRolePermissions(role string) []string

GetRolePermissions returns the permissions for a given role

func (*Authorizer) GrantPermission

func (a *Authorizer) GrantPermission(role, permission string)

GrantPermission adds a permission to an existing role

func (*Authorizer) HasPermission

func (a *Authorizer) HasPermission(user *core.User, permission string) bool

HasPermission checks if any of the user's roles grants the specified permission

func (*Authorizer) RevokePermission

func (a *Authorizer) RevokePermission(role, permission string)

RevokePermission removes a permission from a role

type PolicyFunc

type PolicyFunc func(user *core.User, resource interface{}) bool

PolicyFunc defines a function that checks whether a user can perform an action on a resource

Jump to

Keyboard shortcuts

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