Documentation
¶
Overview ¶
Package admin is a small read-only admin battery for GoFastr apps — stock screens on top of the data the framework already collects: queue jobs (when battery/queue is wired) and the audit log (when framework.WithAuditLog is set).
The battery mounts three pages:
GET /admin index with per-section summary cards GET /admin/queue jobs list with ?status= filter GET /admin/audit audit log paged newest-first
Pages are self-contained server-rendered HTML — they don't depend on framework/uihost or the runtime, so the admin endpoints work even before any UI host is mounted. Wire your own auth middleware in front of them; nothing here gates access.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Battery ¶
type Battery struct {
// contains filtered or unexported fields
}
Battery is the framework Battery implementation.
func New ¶
New constructs the Admin battery with the supplied config. Pass the result to framework.App.RegisterBattery.
func (*Battery) Init ¶
Init implements framework.Battery. Mounts the three admin pages on the App's router under cfg.PathPrefix.
func (*Battery) RegisterRoutes ¶
RegisterRoutes mounts the three admin pages under cfg.PathPrefix on the supplied router. Exposed so apps that compose their own router can mount the admin without going through the battery lifecycle.
type Config ¶
type Config struct {
// PathPrefix is the URL prefix under which admin pages mount.
// Defaults to "/admin".
PathPrefix string
// Title is the title shown at the top of every admin page.
// Defaults to "Admin".
Title string
// Queue is the optional Browsable queue. When set, /admin/queue is
// active. When nil, that page returns a "no queue wired" stub so
// the route never 404s ambiguously.
Queue queue.Browsable
// DB is the database connection used to read the audit log table.
// When nil, /admin/audit returns a "no audit log wired" stub.
DB *sql.DB
// AuditTable is the audit log table name. Defaults to "audit_log".
AuditTable string
// QueueListLimit caps rows on /admin/queue. Default 200.
QueueListLimit int
// AuditListLimit caps rows on /admin/audit. Default 200.
AuditListLimit int
// Entities lists the entity names to expose as editable CRUD screens
// under <PathPrefix>/e/<table>. When empty (default), the battery exposes
// EVERY registered entity whose CRUD is enabled — the "generate the whole
// back-office" default. CRUD-disabled entities (e.g. battery/auth's
// users/sessions, which ship CRUD=false) are skipped automatically, so the
// default never exposes credential tables. Name an entity explicitly to
// override (including a CRUD=false one, if you really mean to). Screens
// proxy to each entity's own CrudHandler, so validation, owner/tenant
// scope, hooks, and events all apply exactly as on the JSON API.
Entities []string
// Authorize gates every admin surface — both the SSR screens (via the UI
// host's policy chain) and the RPC/form routes (via middleware). It returns
// true to allow the request. When nil, the default authorizer requires an
// authenticated user that holds the AdminRole (see below) — a user whose
// GetRoles() []string includes it. Supply a custom predicate to override
// the role check entirely (e.g. a permission lookup, an allow-list).
Authorize func(ctx context.Context) bool
// AdminRole is the role the default authorizer requires (when Authorize is
// nil). Defaults to "admin". Ignored when Authorize is set.
AdminRole string
// EntityListLimit caps rows per page on an entity list screen. Default 50.
EntityListLimit int
}
Config configures the Admin battery.