Documentation
¶
Overview ¶
Package settingadmin provides a standalone settings admin interface following the folder-per-controller pattern. Each controller is in its own subfolder and handles its own views and AJAX data.
It supports two controllers:
- "settings" — a grouped editor driven by a declarative schema (AdminOptions.Groups); each field type renders through an embedded template file (templates/fields/field_<type>.html).
- "manager" — a raw key/value table for arbitrary settings.
This module is modeled on github.com/dracory/logadmin and github.com/dracory/shopadmin.
Index ¶
Constants ¶
const ( FIELD_TYPE_INPUT = shared.FIELD_TYPE_INPUT FIELD_TYPE_TEXTAREA = shared.FIELD_TYPE_TEXTAREA FIELD_TYPE_SELECT = shared.FIELD_TYPE_SELECT FIELD_TYPE_CHECKBOX = shared.FIELD_TYPE_CHECKBOX FIELD_TYPE_NUMBER = shared.FIELD_TYPE_NUMBER FIELD_TYPE_DATE = shared.FIELD_TYPE_DATE FIELD_TYPE_DATETIME = shared.FIELD_TYPE_DATETIME FIELD_TYPE_EMAIL = shared.FIELD_TYPE_EMAIL FIELD_TYPE_PASSWORD = shared.FIELD_TYPE_PASSWORD FIELD_TYPE_URL = shared.FIELD_TYPE_URL FIELD_TYPE_TEL = shared.FIELD_TYPE_TEL FIELD_TYPE_COLOR = shared.FIELD_TYPE_COLOR FIELD_TYPE_RADIO = shared.FIELD_TYPE_RADIO FIELD_TYPE_HIDDEN = shared.FIELD_TYPE_HIDDEN FIELD_TYPE_HTMLAREA = shared.FIELD_TYPE_HTMLAREA FIELD_TYPE_FILE = shared.FIELD_TYPE_FILE FIELD_TYPE_IMAGE = shared.FIELD_TYPE_IMAGE FIELD_TYPE_RAW = shared.FIELD_TYPE_RAW FIELD_TYPE_FALLBACK = shared.FIELD_TYPE_FALLBACK )
Field type constants. Each type maps to an embedded template file templates/fields/field_<type>.html. Unknown types fall back to field_fallback.html.
Variables ¶
var ( // ErrStoreRequired is returned when Store is not provided ErrStoreRequired = errors.New("store is required") // ErrLoggerRequired is returned when Logger is not provided ErrLoggerRequired = errors.New("logger is required") )
Functions ¶
This section is empty.
Types ¶
type AdminInterface ¶
type AdminInterface interface {
Handle(w http.ResponseWriter, r *http.Request)
}
AdminInterface defines the interface for the setting admin
func New ¶
func New(opts AdminOptions) (AdminInterface, error)
New creates a new setting admin instance. Returns ErrStoreRequired if Store is nil, ErrLoggerRequired if Logger is nil.
type AdminOptions ¶
type AdminOptions struct {
// Store is the settingstore.StoreInterface (required)
Store settingstore.StoreInterface
// Logger is required
Logger *slog.Logger
// Groups is the declarative schema for the grouped settings editor.
// Each group's fields are rendered via the FieldRegistry templates.
// Optional — when empty, the "manager" controller becomes default.
Groups []SettingGroup
// FieldTemplates overrides or extends the embedded field templates.
// Key = field type (e.g. "input", "mytype"), value = template text.
FieldTemplates map[string]string
// FuncLayout is an optional function to render the admin interface
// inside your own layout (branding, menus, etc.). If nil, a default
// bare-bones HTML page is used (Bootstrap + Vue CDN).
FuncLayout func(w http.ResponseWriter, r *http.Request, title string, body string, options struct {
Styles []string
StyleURLs []string
Scripts []string
ScriptURLs []string
}) string
// AdminHomeURL is the URL for the admin home page (default: "/admin")
AdminHomeURL string
// SettingAdminURL is the base URL for setting admin
// (default: "/admin/settings")
SettingAdminURL string
// FileManagerURL is the URL for the file manager (optional)
FileManagerURL string
// AuthUserID returns the authenticated user ID from the request.
// If it returns "", the user is treated as unauthenticated.
AuthUserID func(r *http.Request) string
}
AdminOptions contains all dependencies and configuration for the setting admin.
type Field ¶
Field describes a single editable setting. Field.Name is the key used to persist the value in the settingstore. Field.DefaultValue is used when the store has no value for the key. Alias of shared.Field.
type FieldOption ¶
type FieldOption = shared.FieldOption
FieldOption represents a single selectable option for select, radio, and checkbox fields. Alias of shared.FieldOption.
type FieldRegistry ¶
type FieldRegistry struct {
// contains filtered or unexported fields
}
FieldRegistry renders setting fields using one template file per field type. Templates are embedded under templates/fields/field_<type>.html. Host applications can override existing types or register new ones via AdminOptions.FieldTemplates.
func NewFieldRegistry ¶
func NewFieldRegistry(overrides map[string]string) (*FieldRegistry, error)
NewFieldRegistry parses the embedded field templates and merges any overrides (key = field type, value = template text).
func (*FieldRegistry) HasType ¶
func (r *FieldRegistry) HasType(fieldType string) bool
HasType reports whether a template exists for the given field type.
func (*FieldRegistry) Render ¶
Render renders a single field with the given current value. Unknown types fall back to the fallback template, or a plain text input template when no fallback is registered.
func (*FieldRegistry) Types ¶
func (r *FieldRegistry) Types() []string
Types returns the registered field type names.
type SettingGroup ¶
type SettingGroup = shared.SettingGroup
SettingGroup groups related fields under a titled card in the admin UI. Alias of shared.SettingGroup.

