Versions in this module Expand all Collapse all v0 v0.2.0 Oct 23, 2026 Changes in this version + const DefaultPageSize + const MaxPageSize + var ErrConflict = errors.New("permission: conflict") + var ErrInvalid = errors.New("permission: invalid input") + var ErrNotFound = errors.New("permission: not found") + type ScopedResource interface + PermissionScope func() string + type SubjectPage struct + Next Subject + Subjects []Subject + type SubjectQuery struct + After Subject + Limit int + Role string + Scope string + func (q SubjectQuery) Validate() error + type SubjectsOptions struct + After Subject + Limit int v0.1.0 Oct 23, 2026 Changes in this version + const DefaultCacheMaxEntries + const DefaultCacheTTL + const GlobalScope + const MaxDescriptionLength + const MaxNameLength + const MaxPermissionLength + const MaxScopeLength + const MaxSubjectIDLength + var ErrForbidden = errors.New("permission: forbidden") + var ErrInvalidPermission = errors.New("permission: invalid permission") + var ErrInvalidPolicy = errors.New("permission: invalid policy") + var ErrInvalidRole = errors.New("permission: invalid role") + var ErrInvalidScope = errors.New("permission: invalid scope") + var ErrInvalidSubject = errors.New("permission: invalid subject") + var ErrNoPolicy = errors.New("permission: no policy registered") + var ErrPermissionNotFound = errors.New("permission: permission not found") + var ErrRoleExists = errors.New("permission: role already exists") + var ErrRoleNotFound = errors.New("permission: role not found") + func Deny(reason string) error + func Match(granted, p string) bool + func MustRegisterPolicy[T any](a *Authorizer, action string, fn PolicyFunc[T]) + func RegisterPolicy[T any](a *Authorizer, action string, fn PolicyFunc[T]) error + func ScopeFrom(ctx context.Context) string + func ValidatePermission(p string) error + func ValidateRole(name string) error + func ValidateScope(scope string) error + func ValidateSubject(s Subject) error + func WithScope(ctx context.Context, scope string) context.Context + func WithSubject(ctx context.Context, s Subject) context.Context + type Authorizer struct + func New(store Store, opts Options) (*Authorizer, error) + func (a *Authorizer) Allows(ctx context.Context, actor Subject, action string, resource any) bool + func (a *Authorizer) AssignRole(ctx context.Context, subject Subject, role, scope string) error + func (a *Authorizer) Authorize(ctx context.Context, actor Subject, action string, resource any) error + func (a *Authorizer) Can(ctx context.Context, subject Subject, permission, scope string) (bool, error) + func (a *Authorizer) CreateRole(ctx context.Context, name, description string) (Role, error) + func (a *Authorizer) DeletePermission(ctx context.Context, permission string) error + func (a *Authorizer) DeleteRole(ctx context.Context, name string) error + func (a *Authorizer) Grant(ctx context.Context, subject Subject, permission, scope string) error + func (a *Authorizer) GrantToRole(ctx context.Context, role string, permissions ...string) error + func (a *Authorizer) HasAllRoles(ctx context.Context, subject Subject, roles []string, scope string) (bool, error) + func (a *Authorizer) HasAnyRole(ctx context.Context, subject Subject, roles []string, scope string) (bool, error) + func (a *Authorizer) HasRole(ctx context.Context, subject Subject, role, scope string) (bool, error) + func (a *Authorizer) Invalidate(inv Invalidation) + func (a *Authorizer) ListPermissions(ctx context.Context) ([]string, error) + func (a *Authorizer) ListRoles(ctx context.Context) ([]Role, error) + func (a *Authorizer) PermissionsFor(ctx context.Context, subject Subject, scope string) ([]string, error) + func (a *Authorizer) Revoke(ctx context.Context, subject Subject, permission, scope string) error + func (a *Authorizer) RevokeFromRole(ctx context.Context, role string, permissions ...string) error + func (a *Authorizer) Role(ctx context.Context, name string) (Role, error) + func (a *Authorizer) RolePermissions(ctx context.Context, role string) ([]string, error) + func (a *Authorizer) RolesFor(ctx context.Context, subject Subject, scope string) ([]string, error) + func (a *Authorizer) SubjectsWithRole(ctx context.Context, role, scope string) ([]Subject, error) + func (a *Authorizer) UnassignRole(ctx context.Context, subject Subject, role, scope string) error + type CacheBypass interface + BypassCache func(ctx context.Context) bool + type ForbiddenError struct + Action string + Actor Subject + Err error + Reason string + Resource string + func (e *ForbiddenError) Error() string + func (e *ForbiddenError) Is(target error) bool + func (e *ForbiddenError) Unwrap() error + type Grants struct + Permissions []string + Roles []string + type Invalidation struct + All bool + Subject Subject + type Options struct + CacheMaxEntries int + CacheTTL time.Duration + Now func() time.Time + OnError func(ctx context.Context, err error) + SuperAdmin func(ctx context.Context, subject Subject, scope string) (bool, error) + SuperAdminRole string + type PolicyFunc func(ctx context.Context, actor Subject, resource T) (bool, error) + type Role struct + CreatedAt time.Time + Description string + ID uuid.UUID + Name string + func (r Role) Validate() error + type Store interface + AssignRole func(ctx context.Context, subject Subject, role, scope string) error + CreateRole func(ctx context.Context, role Role) error + DeletePermission func(ctx context.Context, permission string) error + DeleteRole func(ctx context.Context, name string) error + Effective func(ctx context.Context, subject Subject, scope string) (Grants, error) + Grant func(ctx context.Context, subject Subject, permission, scope string) error + GrantToRole func(ctx context.Context, role string, permissions []string) error + ListPermissions func(ctx context.Context) ([]string, error) + ListRoles func(ctx context.Context) ([]Role, error) + Revoke func(ctx context.Context, subject Subject, permission, scope string) error + RevokeFromRole func(ctx context.Context, role string, permissions []string) error + Role func(ctx context.Context, name string) (Role, error) + RolePermissions func(ctx context.Context, role string) ([]string, error) + SubjectsWithRole func(ctx context.Context, role, scope string) ([]Subject, error) + UnassignRole func(ctx context.Context, subject Subject, role, scope string) error + type Subject struct + ID string + Type string + func SubjectFrom(ctx context.Context) (Subject, bool) + func (s Subject) IsZero() bool + func (s Subject) String() string