roles

package
v0.4.22 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 0 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package roles defines typed role values passed to ms.RequirePermission.

Typed values prevent typos ("Admian", "VIEWER"), enable IDE autocomplete, and reserve space for future i18n / hierarchy metadata without breaking the call-site API. The canonical roles are Admin and Viewer; Custom accepts any string for module-specific roles.

ms.RegisterPermission takes a DEFAULT role (Admin is always implicit, so it's only passed to mean "admin-only") plus optional custom role keys; routes then gate on the declared permission by name via ms.RequirePermission:

import p "github.com/mirrorstack-ai/app-module-sdk/roles"

ms.RegisterPermission("media.view", ms.PermissionOpts{DefaultRole: p.Viewer()})              // admin implicit; viewer default
ms.RegisterPermission("media.delete", ms.PermissionOpts{DefaultRole: p.Admin()})             // admin-only
ms.RegisterPermission("media.moderate", ms.PermissionOpts{DefaultRole: p.Viewer(), CustomRoles: []string{"moderator"}})
r.With(ms.RequirePermission("media.view")).Get(...)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Keys

func Keys(rs []Role) []string

Keys returns the bare role keys from a slice of Role, preserving order. Used internally by ms.RequirePermission to interoperate with auth's string-based middleware.

Types

type Role

type Role struct {
	Key string
}

Role is a typed wrapper around a role key. Equality comparisons use Key.

func Admin

func Admin() Role

Admin returns the canonical administrator role.

func Custom

func Custom(key string) Role

Custom returns a Role with the given arbitrary key. Use when Admin/Viewer don't fit — typically for module-specific roles like "moderator" or "billing_ops". Panics on empty key.

func Viewer

func Viewer() Role

Viewer returns the canonical read-only role.

Jump to

Keyboard shortcuts

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