admin

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package admin holds shared helpers for the /admin/v1 HTTP surface: RFC 7807 problem+json marshalling and keyset cursor encoding.

Index

Constants

View Source
const (
	CodeForbidden         = "rbac.forbidden"
	CodeOrgMismatch       = "rbac.org_mismatch"
	CodeNoActiveOrg       = "rbac.no_active_org"
	CodeRoleInUse         = "rbac.role_in_use"
	CodeUnknownPermission = "rbac.unknown_permission"
	CodeBadCursor         = "pagination.bad_cursor"
	CodeUserNotInOrg      = "admin.user_not_in_org"
	CodeValidationInvalid = "validation.invalid"
	CodeNotFound          = "admin.not_found"
	CodeInternal          = "admin.internal"
	CodeUnauthorized      = "auth.unauthorized"
	CodeUnsupportedAction = "admin.unsupported_action"
)

Reserved problem codes. Listed here so the admin handlers and the middleware both pull from the same source of truth.

View Source
const ProblemTypeBase = "https://theauth.dev/problems/"

ProblemTypeBase is the URI prefix for problem types per RFC 7807. Each problem code is appended to form the canonical type URI. Consumers may host their own equivalent page; the URI is informational only.

Variables

This section is empty.

Functions

func DecodeCursor

func DecodeCursor(s string) (time.Time, ulid.ULID, error)

DecodeCursor reverses EncodeCursor. Returns an error on any malformed input; handlers map the error to a 400 problem+json with code "pagination.bad_cursor".

func EncodeCursor

func EncodeCursor(ts time.Time, id ulid.ULID) string

EncodeCursor returns a URL-safe base64 string of "<unix_micros>:<ulid>". Decoding is symmetric and tolerant of any input that round-trips back to a parsable (int64, ULID) pair; everything else returns an error.

func Write

func Write(w http.ResponseWriter, status int, code, detail, instance string)

Write emits a single problem+json response. status drives both the HTTP status code and the body's "status" field so the two cannot drift.

Types

type Problem

type Problem struct {
	Type     string `json:"type"`
	Title    string `json:"title"`
	Status   int    `json:"status"`
	Detail   string `json:"detail,omitempty"`
	Instance string `json:"instance,omitempty"`
	Code     string `json:"code"`
}

Problem is the RFC 7807 application/problem+json document shape, plus the "code" extension this library uses for machine-readable error matching.

Jump to

Keyboard shortcuts

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