Documentation
¶
Overview ¶
Package permission provides fixed-size bitmask types, a permission registry, and role composition helpers used by goAuth authorization checks.
Mask sizes ¶
Supported widths: 64, 128, 256, and 512 bits. A mask is selected at registry construction time and is immutable thereafter. Bit positions are assigned by Registry.Register and are stable for the lifetime of the process.
Architecture boundaries ¶
This package is a pure in-memory data structure with no I/O. It provides the codec (Encode/Decode) used by the session binary encoder.
What this package must NOT do ¶
- Access Redis, databases, or the network.
- Import goAuth, jwt, or session.
- Dynamically resize masks after registry construction.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeMask ¶
DecodeMask deserializes a byte slice back into a typed permission mask (Mask64, Mask128, Mask256, or Mask512).
Performance: O(1). Docs: docs/permission.md, docs/jwt.md
func EncodeMask ¶
EncodeMask serializes a permission bitmask into a byte slice for JWT embedding.
Performance: O(1), single allocation. Docs: docs/permission.md, docs/jwt.md
Types ¶
type Mask64 ¶
type Mask64 uint64
Mask64 is a 64-bit permission bitmask supporting up to 64 permissions.
type Mask128 ¶
Mask128 is a 128-bit permission bitmask supporting up to 128 permissions.
type Mask256 ¶
Mask256 is a 256-bit permission bitmask supporting up to 256 permissions.
type Mask512 ¶
Mask512 is a 512-bit permission bitmask supporting up to 512 permissions.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maps permission names to bit positions within a bitmask. Supports widths of 64, 128, 256, or 512 bits.
Docs: docs/permission.md
func NewRegistry ¶
NewRegistry creates a permission Registry that maps permission names to bit positions. maxBits selects the mask width (64/128/256/512); rootBitReserved reserves bit 0 for a super-admin root permission.
Docs: docs/permission.md
func (*Registry) Bit ¶
Bit returns the bit index for the named permission, or false if not registered.
func (*Registry) Freeze ¶
func (r *Registry) Freeze()
Freeze prevents further registrations. Must be called before the registry is used for validation.
func (*Registry) Name ¶
Name returns the permission name for the given bit index, or false if unassigned.
func (*Registry) Register ¶
Register assigns the next available bit to the named permission. Returns the assigned bit index. Must be called before Registry.Freeze.
Docs: docs/permission.md
type RoleManager ¶
type RoleManager struct {
// contains filtered or unexported fields
}
RoleManager maps role names to pre-computed permission bitmasks. After RoleManager.Freeze, masks are immutable and safe for concurrent reads.
Docs: docs/permission.md
func NewRoleManager ¶
func NewRoleManager(registry *Registry) *RoleManager
NewRoleManager creates a RoleManager backed by the given Registry.
Docs: docs/permission.md
func (*RoleManager) Count ¶
func (rm *RoleManager) Count() int
Count returns the number of registered roles.
func (*RoleManager) Freeze ¶
func (rm *RoleManager) Freeze()
Freeze prevents further role registrations.
func (*RoleManager) GetMask ¶
func (rm *RoleManager) GetMask(roleName string) (interface{}, bool)
GetMask returns the pre-computed bitmask for the named role, or false if the role is not registered.
func (*RoleManager) RegisterRole ¶
func (rm *RoleManager) RegisterRole( roleName string, permissionNames []string, maxBits int, rootReserved bool, ) error
RegisterRole creates a role with the given permissions and registers it. Must be called before RoleManager.Freeze.
Docs: docs/permission.md