Documentation
¶
Overview ¶
Package blogadmin provides a standalone blog admin interface following the folder-per-controller pattern. Each controller is in its own subfolder and handles its own views and AJAX data.
This module is modeled on github.com/dracory/shopadmin.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrStoreRequired is returned when Store is not provided ErrStoreRequired = errors.New("blog store is required") // ErrLoggerRequired is returned when Logger is not provided ErrLoggerRequired = errors.New("logger is required") // ErrAIEnabledMissingLlmFactory is returned when AIEnabled is true // but LlmFactory is nil. AI controllers need an LLM engine to run. ErrAIEnabledMissingLlmFactory = errors.New("AIEnabled is true but LlmFactory is nil — provide an LlmFactory or set AIEnabled to false") // ErrAIEnabledMissingCustomStore is returned when AIEnabled is true // but CustomStore is nil. AI controllers persist generated content // and approved titles through CustomStore. ErrAIEnabledMissingCustomStore = errors.New("AIEnabled is true but CustomStore is nil — provide a CustomStore or set AIEnabled to false") // ErrAIEnabledMissingSettingStore is returned when AIEnabled is true // but SettingStore is nil. The AI title generator reads its model // and prompt settings from SettingStore. ErrAIEnabledMissingSettingStore = errors.New("AIEnabled is true but SettingStore is nil — provide a SettingStore or set AIEnabled to false") )
Common errors
Functions ¶
This section is empty.
Types ¶
type AdminInterface ¶
type AdminInterface interface {
Handle(w http.ResponseWriter, r *http.Request)
}
AdminInterface defines the interface for the blog admin
func New ¶
func New(opts AdminOptions) (AdminInterface, error)
New creates a new blog admin instance. Returns ErrStoreRequired if Store is nil, ErrLoggerRequired if Logger is nil.
When AIEnabled is true, the AI dependencies are also required: ErrAIEnabledMissingLlmFactory if LlmFactory is nil, ErrAIEnabledMissingCustomStore if CustomStore is nil, ErrAIEnabledMissingSettingStore if SettingStore is nil. This makes misconfiguration fail fast at construction instead of surfacing as runtime errors inside individual AI controllers.
type AdminOptions ¶
type AdminOptions struct {
// Store is the blogstore.StoreInterface (required)
Store blogstore.StoreInterface
// Logger is required
Logger *slog.Logger
// CustomStore is required for AI controllers (ai_title_generator,
// ai_post_generator, ai_post_editor). Nil means AI controllers
// that need it return an error to the user.
CustomStore customstore.StoreInterface
// SettingStore is required for ai_title_generator. Nil means the
// title generator returns an error when reading settings.
SettingStore settingstore.StoreInterface
// LlmFactory creates an LLM engine instance. Required for all AI
// controllers. Nil means AI controllers return an error to the user.
LlmFactory shared.LlmFactoryFunc
// AIEnabled controls whether AI features are available. When false
// (the default), AI routes are not registered and AI navigation
// links are hidden. Set to true to enable AI features; you should
// also provide LlmFactory, CustomStore, and SettingStore.
AIEnabled bool
// FuncLayout is an optional function to render the admin interface
// inside your own layout (branding, menus, etc.). It receives the
// request and response writer so the host project can access request
// context (auth user, locale, etc.) when rendering the layout.
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
// BlogAdminURL is the base URL for blog admin (default: "/admin/blog")
BlogAdminURL 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 blog admin.
Store and Logger are required. CustomStore, SettingStore, and LlmFactory are required only for the AI controllers; if nil, AI controllers return an error to the user instead of panicking.
AIEnabled gates the AI controllers (ai_tools, ai_test, ai_post_generator, ai_title_generator, ai_post_editor, ai_post_content_update). When false (the default), AI routes are not registered and AI navigation links are hidden. Set to true to enable AI features, and provide LlmFactory, CustomStore, and SettingStore as well.
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). Uses anonymous struct to match shopadmin exactly, so consumers can reuse their shopadmin layout function for blogadmin.