admin

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package admin is a resource-based CRUD admin panel for Nimbus, modeled on Laravel Nova / Filament. You describe your models as Resources (fields + display rules) and the panel auto-generates list, create, edit, and delete screens with a modern Tailwind UI.

panel := admin.New(db, admin.Config{
    BrandName:  "Acme Admin",
    Middleware: []router.Middleware{auth.RequireAuth(guard)}, // gate the panel
})
panel.AddResource(admin.Resource{
    Model:  &models.Post{},
    Fields: []admin.Field{
        admin.Text("Title").AsSortable(),
        admin.Textarea("Body"),
        admin.Boolean("Published"),
    },
})
app.Use(panel)

With no Fields, the panel infers them from the struct. The panel operates on your existing tables — it declares no migrations of its own.

Layout:

admin.go     – plugin + panel + Config    resource.go – Resource, Field, reflection
routes.go    – CRUD handlers              views/      – layout, list, form, dashboard

Index

Constants

View Source
const (
	TypeText     = "text"
	TypeTextarea = "textarea"
	TypeNumber   = "number"
	TypeBoolean  = "boolean"
	TypeEmail    = "email"
	TypePassword = "password"
	TypeDate     = "date"
	TypeSelect   = "select"
)

Field types understood by the form renderer.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// RoutePrefix is where the panel mounts. Default "/admin".
	RoutePrefix string
	// BrandName shown in the sidebar header. Default "Nimbus Admin".
	BrandName string
	// Middleware gates every panel route (e.g. an auth guard). Strongly
	// recommended — without it the panel is public.
	Middleware []router.Middleware
}

Config tunes the admin panel.

type Field

type Field struct {
	Name     string // Go struct field name (also the display key)
	Label    string
	Type     string
	Options  []Option // for TypeSelect
	OnIndex  bool     // show in the list table
	OnForm   bool     // show in the create/edit form
	Readonly bool     // rendered disabled on the form
	Sortable bool
}

Field describes one column/attribute of a resource.

func Boolean

func Boolean(name string) Field

Boolean is a checkbox field.

func Date

func Date(name string) Field

Date is a date input.

func Email

func Email(name string) Field

Email is an email input.

func Number

func Number(name string) Field

Number is a numeric field.

func Password

func Password(name string) Field

Password is a write-only password field (never shown on the index, blank on edit).

func Select

func Select(name string, opts ...Option) Field

Select is a dropdown with fixed options.

func Text

func Text(name string) Field

Text is a single-line text field.

func Textarea

func Textarea(name string) Field

Textarea is a multi-line text field (hidden from the index by default).

func (Field) AsReadonly

func (f Field) AsReadonly() Field

AsReadonly renders the field disabled on the form.

func (Field) AsSortable

func (f Field) AsSortable() Field

AsSortable marks the field sortable in the index.

func (Field) HideFromForm

func (f Field) HideFromForm() Field

HideFromForm removes the field from create/edit forms.

func (Field) HideFromIndex

func (f Field) HideFromIndex() Field

HideFromIndex removes the field from the list table.

func (Field) WithLabel

func (f Field) WithLabel(l string) Field

WithLabel overrides the display label.

type Option

type Option struct {
	Value string
	Label string
}

Option is a choice for a select field.

type Panel

type Panel struct {
	// contains filtered or unexported fields
}

Panel holds the registered resources and the database handle.

type Plugin

type Plugin struct {
	nimbus.BasePlugin
	// contains filtered or unexported fields
}

Plugin wires the admin panel into Nimbus.

func New

func New(db *lucid.DB, cfg Config) *Plugin

New builds an admin panel over the given database.

func (*Plugin) AddResource

func (p *Plugin) AddResource(r Resource) *Plugin

AddResource registers a resource with the panel. Chainable.

func (*Plugin) Boot

func (p *Plugin) Boot(app *nimbus.App) error

func (*Plugin) DefaultConfig

func (p *Plugin) DefaultConfig() map[string]any

func (*Plugin) Panel

func (p *Plugin) Panel() *Panel

Panel exposes the underlying panel (for advanced use / testing).

func (*Plugin) Register

func (p *Plugin) Register(app *nimbus.App) error

func (*Plugin) RegisterRoutes

func (p *Plugin) RegisterRoutes(r *router.Router)

RegisterRoutes mounts the admin panel under the configured prefix, behind any configured gate middleware:

GET  /admin                    dashboard
GET  /admin/:slug              list (paginated)
GET  /admin/:slug/create       create form
POST /admin/:slug              store
GET  /admin/:slug/:id/edit     edit form
POST /admin/:slug/:id          update
POST /admin/:slug/:id/delete   destroy

func (*Plugin) ViewsFS

func (p *Plugin) ViewsFS() fs.FS

ViewsFS returns the embedded admin templates for the view engine.

type Resource

type Resource struct {
	// Model is a pointer to a zero value of the model, e.g. &models.Post{}.
	Model any
	// Label is the plural display name ("Posts"). Defaults from the type name.
	Label string
	// Singular display name ("Post").
	Singular string
	// Slug is the URL segment ("posts"). Defaults from the type name.
	Slug string
	// Fields to display. When empty, fields are inferred from the struct.
	Fields []Field
	// PerPage rows on the index. Default 15.
	PerPage int
	// contains filtered or unexported fields
}

Resource maps a database model to an admin CRUD screen.

Jump to

Keyboard shortcuts

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