Documentation
¶
Overview ¶
Package shopadmin provides a standalone shop 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/cmsstore/admin.
Index ¶
Constants ¶
This section is empty.
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") // ErrRegistryRequired is returned when Registry is not provided // (kept for backward compatibility with Routes()) ErrRegistryRequired = errors.New("registry is required") )
Functions ¶
func Routes ¶
func Routes(registry RegistryInterface, opts ...AdminOptions) ([]rtr.RouteInterface, error)
Routes returns the routes for the shop admin, for integration with the host project's router. The signature preserves the original Routes(registry, opts...) form — registry is RegistryInterface (structurally compatible with project/internal/app.AppInterface), so existing call sites like shopadmin.Routes(app, opts) work unchanged.
Types ¶
type AdminInterface ¶
type AdminInterface interface {
Handle(w http.ResponseWriter, r *http.Request)
}
AdminInterface defines the interface for the shop admin
func New ¶
func New(opts AdminOptions) (AdminInterface, error)
New creates a new shop admin instance. Returns ErrStoreRequired if Store is nil, ErrLoggerRequired if Logger is nil.
type AdminOptions ¶
type AdminOptions struct {
// Store is the shopstore.StoreInterface (required)
Store shopstore.StoreInterface
// Logger is required (matches cmsstore requirement)
Logger *slog.Logger
// CustomerResolver resolves customer data for order views.
// Optional — nil means customer fields stay empty and customer
// filtering is disabled. Called by order_details and order_manager.
CustomerResolver CustomerResolverInterface
// 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 cmsstore/admin exactly, so consumers
// can reuse their cmsstore layout function for shopadmin.
FuncLayout func(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
// ShopAdminURL is the base URL for shop admin (default: "/admin/shop")
ShopAdminURL 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 shop admin.
Store, CacheStore, and Logger replace the in-repo version's Registry field (which was app.AppInterface). This matches the cmsstore/admin convention where stores are passed directly.
Customer resolution is via CustomerResolverInterface rather than a userstore dependency, keeping shopadmin decoupled from any specific auth/user-management package.
type CustomerResolverInterface ¶
type CustomerResolverInterface = shared.CustomerResolverInterface
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.).
This is a re-export of shared.CustomerResolverInterface so consumers of the root shopadmin package can use shopadmin.CustomerResolverInterface without importing the shared subpackage.
type RegistryInterface ¶
type RegistryInterface interface {
GetShopStore() shopstore.StoreInterface
GetLogger() *slog.Logger
}
RegistryInterface provides access to the stores and services that shopadmin needs. It is structurally compatible with project/internal/app.AppInterface — any type implementing AppInterface already satisfies this narrower interface.
This interface exists so that Routes() can preserve its original signature Routes(registry, opts...) without importing project/internal/app.
GetUserStore() is intentionally absent — customer resolution is handled via FindCustomer / SearchCustomerIDs function fields in AdminOptions, keeping shopadmin decoupled from userstore.