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
- type Config
- type Field
- type Option
- type Panel
- type Plugin
- func (p *Plugin) AddResource(r Resource) *Plugin
- func (p *Plugin) Boot(app *nimbus.App) error
- func (p *Plugin) DefaultConfig() map[string]any
- func (p *Plugin) Panel() *Panel
- func (p *Plugin) Register(app *nimbus.App) error
- func (p *Plugin) RegisterRoutes(r *router.Router)
- func (p *Plugin) ViewsFS() fs.FS
- type Resource
Constants ¶
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 (Field) AsReadonly ¶
AsReadonly renders the field disabled on the form.
func (Field) AsSortable ¶
AsSortable marks the field sortable in the index.
func (Field) HideFromForm ¶
HideFromForm removes the field from create/edit forms.
func (Field) HideFromIndex ¶
HideFromIndex removes the field from the list table.
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 (*Plugin) AddResource ¶
AddResource registers a resource with the panel. Chainable.
func (*Plugin) DefaultConfig ¶
func (*Plugin) RegisterRoutes ¶
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
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.