Help us shape the future of Go! Take the 2026 Go Developer Survey

rbac

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package rbac defines roles and permissions for the auth module.

A permission is a specific action named "resource:action", such as "invoices:create". A role is a named set of permissions. Roles live in Go code, not the database, so every change to who can do what goes through code review. Code checks permissions, never role names, so roles can change without hunting through handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Permission

type Permission string

Permission is an action, named "resource:action": lowercase letters, digits, and underscores on each side of the colon.

const All Permission = "*"

All grants every permission. Give it only to roles such as an organization's owner.

type Roles

type Roles map[string][]Permission

Roles maps role names to the permissions they grant. Role names are lowercase letters, digits, and underscores, starting with a letter.

func (Roles) Defines

func (r Roles) Defines(role string) bool

Defines reports whether role exists.

func (Roles) Has

func (r Roles) Has(role string, p Permission) bool

Has reports whether role grants p. An unknown role grants nothing.

func (Roles) Mentions

func (r Roles) Mentions(p Permission) bool

Mentions reports whether any role lists p by name. All doesn't count: it's used to catch permissions that are misspelled where they're required, which a role with All would otherwise hide.

func (Roles) Validate

func (r Roles) Validate() error

Validate checks every role name and permission is well formed, so a typo fails at startup instead of silently denying access.

Jump to

Keyboard shortcuts

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