Documentation
¶
Index ¶
- Constants
- func AdminHomeURL(r *http.Request) string
- func Breadcrumbs(breadcrumbs []Breadcrumb) hb.TagInterface
- func Endpoint(r *http.Request) string
- func ErrorAlert(message string) string
- func FileManagerURL(r *http.Request) string
- func Header(store shopstore.StoreInterface, logger *slog.Logger, r *http.Request) hb.TagInterface
- func Layout(w http.ResponseWriter, r *http.Request, webpageTitle, webpageHtml string, ...) string
- func ShopAdminURL(r *http.Request) string
- func URL(endpoint string, controller string, params map[string]string) string
- func URLR(r *http.Request, controller string, params map[string]string) string
- type Breadcrumb
- type CustomerResolverInterface
- type Links
- func (l *Links) Categories(params map[string]string) string
- func (l *Links) CategoryCreate(params map[string]string) string
- func (l *Links) CategoryUpdate(params map[string]string) string
- func (l *Links) DiscountUpdate(params map[string]string) string
- func (l *Links) DiscountView(params map[string]string) string
- func (l *Links) Discounts(params map[string]string) string
- func (l *Links) Home(params map[string]string) string
- func (l *Links) OrderDetails(params map[string]string) string
- func (l *Links) Orders(params map[string]string) string
- func (l *Links) ProductUpdate(params map[string]string) string
- func (l *Links) ProductView(params map[string]string) string
- func (l *Links) Products(params map[string]string) string
- type UiBase
- type UiConfig
- type UiInterface
Constants ¶
const ( CONTROLLER_HOME = "home" CONTROLLER_PRODUCTS = "products" CONTROLLER_PRODUCT_VIEW = "product_view" CONTROLLER_PRODUCT_UPDATE = "product_update" CONTROLLER_CATEGORIES = "categories" CONTROLLER_CATEGORY_CREATE = "category_create" CONTROLLER_CATEGORY_UPDATE = "category_update" CONTROLLER_DISCOUNTS = "discounts" CONTROLLER_DISCOUNT_VIEW = "discount_view" CONTROLLER_DISCOUNT_UPDATE = "discount_update" CONTROLLER_ORDERS = "orders" CONTROLLER_ORDER_DETAILS = "order_details" )
Controller names used in the ?controller= query parameter
const CatchAll = "/*"
CatchAll is the catch-all route suffix
const ERROR_LOGGER_IS_NIL = "logger cannot be nil"
const ERROR_STORE_IS_NIL = "store cannot be nil"
Error messages
const KeyAdminHomeURL = "admin_home_url"
const KeyEndpoint = "endpoint"
Context keys for config values injected by Handle()
const KeyFileManagerURL = "file_manager_url"
const KeyShopAdminURL = "shop_admin_url"
Variables ¶
This section is empty.
Functions ¶
func AdminHomeURL ¶
AdminHomeURL returns the admin home URL from request context
func Breadcrumbs ¶
func Breadcrumbs(breadcrumbs []Breadcrumb) hb.TagInterface
Breadcrumbs renders a breadcrumb navigation from the given items
func ErrorAlert ¶
ErrorAlert returns an inline HTML error alert for the given message. This replaces the former ToFlashError flash-message pattern, which required a cache store and a /flash route handler that did not exist.
func FileManagerURL ¶
FileManagerURL returns the file manager URL from request context
func Header ¶
func Header(store shopstore.StoreInterface, logger *slog.Logger, r *http.Request) hb.TagInterface
Header renders the shop admin navigation header. It is nil-safe for both store and logger (fixes pre-existing bug #11).
func Layout ¶
func Layout(w http.ResponseWriter, r *http.Request, webpageTitle, webpageHtml string, options struct { Styles []string StyleURLs []string Scripts []string ScriptURLs []string }) string
Layout is the default layout renderer. It builds a complete HTML page using hb.NewWebpage() with Bootstrap + Vue CDN, matching the cmsstore/admin pattern. If a FuncLayout is provided in AdminOptions, it takes precedence over this default.
func ShopAdminURL ¶
ShopAdminURL returns the shop admin base URL from request context
Types ¶
type Breadcrumb ¶
Breadcrumb represents a single breadcrumb navigation item
type CustomerResolverInterface ¶
type CustomerResolverInterface interface {
// FindByID returns customer display name and email for a given ID.
// Returns empty strings if not found — no error for "not found".
// Called by order_details and order_manager controllers.
FindByID(ctx context.Context, customerID string) (name, email string)
// SearchIDs returns customer IDs matching the given name and/or
// email substrings. Empty string means "no filter on that field".
// Called by order_manager controller.
SearchIDs(ctx context.Context, name, email string) ([]string, error)
}
CustomerResolverInterface resolves customer data for order views. The host project provides an implementation — shopadmin does not care where the data comes from (userstore, CRM, external API, etc.).
All methods are optional — a nil implementation means customer fields stay empty and customer filtering is disabled.
This interface replaces the former userstore dependency, keeping shopadmin decoupled from any specific auth/user-management package.
type Links ¶
type Links struct {
// contains filtered or unexported fields
}
Links provides URL helpers for shopadmin controllers. The base URL is read from request context (injected by Handle()), not hardcoded. This fixes the pre-existing issue where "/admin/shop" was hardcoded in every subcontroller.
func NewLinks ¶
NewLinks creates a Links helper with the given base URL. If baseURL is empty, defaults to "/admin/shop".
func NewLinksFromRequest ¶
NewLinksFromRequest creates a Links helper using the shop admin URL from the request context.
func (*Links) Categories ¶
Categories builds the URL for the categories controller
func (*Links) CategoryCreate ¶
CategoryCreate builds the URL for the category create controller
func (*Links) CategoryUpdate ¶
CategoryUpdate builds the URL for the category update controller
func (*Links) DiscountUpdate ¶ added in v0.2.0
DiscountUpdate builds the URL for the discount update controller
func (*Links) DiscountView ¶ added in v0.2.0
DiscountView builds the URL for the discount view controller
func (*Links) OrderDetails ¶
OrderDetails builds the URL for the order details controller
func (*Links) ProductUpdate ¶
ProductUpdate builds the URL for the product update controller
func (*Links) ProductView ¶ added in v0.2.0
ProductView builds the URL for the product view controller
type UiBase ¶
type UiBase struct {
StoreField shopstore.StoreInterface
LoggerField *slog.Logger
CustomerResolverField CustomerResolverInterface
LayoutField func(w http.ResponseWriter, r *http.Request, webpageTitle, webpageHtml string, options struct {
Styles []string
StyleURLs []string
Scripts []string
ScriptURLs []string
}) string
}
UiBase is a base struct that implements shared.UiInterface. Subcontroller ui structs can embed this to get the Store(), CacheStore(), Logger(), CustomerResolver(), and Layout() methods for free, following the cmsstore/admin pattern.
func (UiBase) CustomerResolver ¶
func (u UiBase) CustomerResolver() CustomerResolverInterface
func (UiBase) Store ¶
func (u UiBase) Store() shopstore.StoreInterface
type UiConfig ¶
type UiConfig struct {
Store shopstore.StoreInterface
Logger *slog.Logger
CustomerResolver CustomerResolverInterface
Layout func(w http.ResponseWriter, r *http.Request, webpageTitle, webpageHtml string, options struct {
Styles []string
StyleURLs []string
Scripts []string
ScriptURLs []string
}) string
}
UiConfig holds the dependencies passed to subcontroller UI factories. The Layout function uses an anonymous struct for options to match cmsstore/admin exactly, allowing consumers to reuse their cmsstore layout function for shopadmin.
Customer resolution is via CustomerResolverInterface rather than a userstore dependency, keeping shopadmin decoupled from any specific auth/user-management package.
type UiInterface ¶
type UiInterface interface {
Store() shopstore.StoreInterface
Logger() *slog.Logger
// CustomerResolver returns the CustomerResolverInterface, or nil.
CustomerResolver() CustomerResolverInterface
Layout(w http.ResponseWriter, r *http.Request, webpageTitle, webpageHtml string, options struct {
Styles []string
StyleURLs []string
Scripts []string
ScriptURLs []string
}) string
}
UiInterface defines the methods every subcontroller UI must implement. This follows the cmsstore/admin pattern.
Customer resolution is via CustomerResolverInterface rather than a userstore dependency.