shared

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
const CatchAll = "/*"

CatchAll is the catch-all route suffix

View Source
const ERROR_LOGGER_IS_NIL = "logger cannot be nil"
View Source
const ERROR_STORE_IS_NIL = "store cannot be nil"

Error messages

View Source
const KeyAdminHomeURL = "admin_home_url"
View Source
const KeyEndpoint = "endpoint"

Context keys for config values injected by Handle()

View Source
const KeyFileManagerURL = "file_manager_url"
View Source
const KeyShopAdminURL = "shop_admin_url"

Variables

This section is empty.

Functions

func AdminHomeURL

func AdminHomeURL(r *http.Request) string

AdminHomeURL returns the admin home URL from request context

func Breadcrumbs(breadcrumbs []Breadcrumb) hb.TagInterface

Breadcrumbs renders a breadcrumb navigation from the given items

func Endpoint

func Endpoint(r *http.Request) string

Endpoint returns the request endpoint URL from context

func ErrorAlert

func ErrorAlert(message string) string

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

func FileManagerURL(r *http.Request) string

FileManagerURL returns the file manager URL from request context

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

func ShopAdminURL(r *http.Request) string

ShopAdminURL returns the shop admin base URL from request context

func URL

func URL(endpoint string, controller string, params map[string]string) string

URL builds a URL for the given endpoint and controller with params. The controller is placed in the params map under the "controller" key. The params map is copied before mutation (does not modify caller's map).

func URLR

func URLR(r *http.Request, controller string, params map[string]string) string

URLR builds a URL using the endpoint from the request context.

Types

type Breadcrumb struct {
	Name string
	URL  string
}

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 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(baseURL string) *Links

NewLinks creates a Links helper with the given base URL. If baseURL is empty, defaults to "/admin/shop".

func NewLinksFromRequest

func NewLinksFromRequest(r *http.Request) *Links

NewLinksFromRequest creates a Links helper using the shop admin URL from the request context.

func (*Links) Categories

func (l *Links) Categories(params map[string]string) string

Categories builds the URL for the categories controller

func (*Links) CategoryCreate

func (l *Links) CategoryCreate(params map[string]string) string

CategoryCreate builds the URL for the category create controller

func (*Links) CategoryUpdate

func (l *Links) CategoryUpdate(params map[string]string) string

CategoryUpdate builds the URL for the category update controller

func (*Links) DiscountUpdate added in v0.2.0

func (l *Links) DiscountUpdate(params map[string]string) string

DiscountUpdate builds the URL for the discount update controller

func (*Links) DiscountView added in v0.2.0

func (l *Links) DiscountView(params map[string]string) string

DiscountView builds the URL for the discount view controller

func (*Links) Discounts

func (l *Links) Discounts(params map[string]string) string

Discounts builds the URL for the discounts controller

func (*Links) Home

func (l *Links) Home(params map[string]string) string

Home builds the URL for the home controller

func (*Links) OrderDetails

func (l *Links) OrderDetails(params map[string]string) string

OrderDetails builds the URL for the order details controller

func (*Links) Orders

func (l *Links) Orders(params map[string]string) string

Orders builds the URL for the orders controller

func (*Links) ProductUpdate

func (l *Links) ProductUpdate(params map[string]string) string

ProductUpdate builds the URL for the product update controller

func (*Links) ProductView added in v0.2.0

func (l *Links) ProductView(params map[string]string) string

ProductView builds the URL for the product view controller

func (*Links) Products

func (l *Links) Products(params map[string]string) string

Products builds the URL for the products 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 NewUiBase

func NewUiBase(config UiConfig) UiBase

NewUiBase creates a UiBase from a UiConfig

func (UiBase) CustomerResolver

func (u UiBase) CustomerResolver() CustomerResolverInterface

func (UiBase) Layout

func (u UiBase) Layout(w http.ResponseWriter, r *http.Request, webpageTitle, webpageHtml string, options struct {
	Styles     []string
	StyleURLs  []string
	Scripts    []string
	ScriptURLs []string
}) string

func (UiBase) Logger

func (u UiBase) Logger() *slog.Logger

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL