Documentation
¶
Overview ¶
Package admin provides Oni Admin — an auto-generated CRUD management panel. Resources are registered with their model type and the panel generates list, create, edit, and delete routes automatically.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authorizer ¶
Authorizer decides whether a request may access the admin panel. It runs before every admin route (HTML and JSON API). Return true to allow.
type Option ¶
type Option func(*Panel)
Option configures the panel.
func WithAuth ¶
func WithAuth(fn Authorizer) Option
WithAuth sets the authorizer that guards every admin route. Without it the panel denies all requests.
admin.New(db, admin.WithAuth(func(r *http.Request) bool {
return guard.IsAdmin(r) // your auth check
}))
func WithPrefix ¶
WithPrefix sets the URL prefix (default: "/admin").
type Panel ¶
type Panel struct {
// contains filtered or unexported fields
}
Panel is the Oni Admin panel.
func New ¶
New creates an Admin panel bound to the given DB.
The panel exposes full read/write/delete access to every registered table, so it MUST be protected by an Authorizer (see WithAuth). If none is configured the panel fails closed: every route returns 403 until WithAuth is provided. This prevents an unauthenticated admin panel from ever shipping by accident.
func (*Panel) APIHandler ¶
APIHandler returns a simple REST JSON API for all registered resources. Mount at a separate prefix for headless admin API access.
type Resource ¶
type Resource struct {
// Name is the human-readable resource name (e.g. "User").
Name string
// Slug is the URL segment (e.g. "users"). Defaults to lowercase Name + "s".
Slug string
// Model is a pointer to the model struct (for reflection).
Model any
// Columns lists which fields to show in the list view. Empty = all exported.
Columns []string
// Searchable is the column name to use for search (default: first string col).
Searchable string
// PerPage controls pagination (default: 25).
PerPage int
// Writable lists the columns that may be set from form input on create and
// edit. Empty = all Columns except the primary key ("id"). The primary key
// is never written from form input regardless of this list — on edit the
// record is addressed by the URL id only.
Writable []string
}
Resource describes a model that the admin panel should expose.