Documentation
¶
Index ¶
- func ComposeLayouts(ctx LoadContext, stack LayoutStack, registry LayoutRegistry, body string) (string, error)
- func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, err error)
- func ElementPath(value any, path string) (any, bool)
- func IsNativeRBACGuard(name string) bool
- func LoadPath(data map[string]any, path string) (any, bool)
- func Redirect(url string, status int) error
- func RedirectTarget(err error) (string, int, bool)
- func RedirectTo(url string) error
- func Register(router Router, routes []Route)
- func RenderRegions(html string, lists []ListSpec, conds []CondSpec, data map[string]any) string
- func RunGuards(ctx LoadContext, names []string, registry GuardRegistry) error
- func RunGuardsWithAuth(ctx LoadContext, names []string, registry GuardRegistry, ...) error
- type CondSpec
- type ErrorHandler
- type GuardFunc
- type GuardRegistry
- type LayoutFunc
- type LayoutRegistry
- type LayoutStack
- type ListField
- type ListSpec
- type LoadContext
- type LoadFunc
- type RedirectError
- type Route
- type Router
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComposeLayouts ¶
func ComposeLayouts(ctx LoadContext, stack LayoutStack, registry LayoutRegistry, body string) (string, error)
ComposeLayouts wraps body with the declared layout stack. Layouts are listed from outermost to innermost, matching layout root, dashboard semantics.
func DefaultErrorHandler ¶
func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, err error)
DefaultErrorHandler renders a conservative SSR failure response.
func ElementPath ¶
ElementPath resolves a dotted field path against an arbitrary value (map, struct, pointer, or interface), mirroring LoadPath's field-matching rules but rooted at a row element or the load data map.
func IsNativeRBACGuard ¶
IsNativeRBACGuard reports whether name is a built-in role or permission guard.
func LoadPath ¶
LoadPath resolves a declared load {} path from generated SSR load data. Supported values are nested maps with string keys, structs, pointers, and interfaces. Struct fields may be matched by exported Go field name or json tag.
func Redirect ¶
Redirect returns an error that generated SSR handlers translate into a no-store local redirect with the provided 3xx status.
func RedirectTarget ¶
RedirectTarget extracts a generated SSR redirect error.
func RedirectTo ¶
RedirectTo returns an error that generated SSR handlers translate into a no-store local redirect.
func RenderRegions ¶
RenderRegions expands every top-level g:for list and g:if conditional in html by resolving their data from the request-time load data. Field values are always HTML-escaped, preserving GOWDK's escape-by-default contract for request-time server data.
func RunGuards ¶
func RunGuards(ctx LoadContext, names []string, registry GuardRegistry) error
RunGuards executes guard IDs in declaration order.
func RunGuardsWithAuth ¶
func RunGuardsWithAuth(ctx LoadContext, names []string, registry GuardRegistry, provider auth.Provider) error
RunGuardsWithAuth executes guard IDs in declaration order and resolves native RBAC guard IDs such as role:admin and permission:posts.write through provider.
Types ¶
type CondSpec ¶
type CondSpec struct {
Placeholder string
// SourcePath is the dotted field path for a simple field/!field condition,
// resolved against the enclosing container. Empty when Expr is set.
SourcePath string
Negate bool
// Expr is a full bool expression (comparisons, logic, literals) evaluated
// against the enclosing container at request time. When set it takes
// precedence over SourcePath/Negate; used for top-level server g:if.
Expr string
Template string
Fields []ListField
Lists []ListSpec
Conds []CondSpec
}
CondSpec describes one server-rendered g:if conditional. Its branch is rendered into the output only when SourcePath resolves to a truthy value (negated when Negate is set). The branch shares the enclosing container scope, so its fields and nested regions resolve against the same data as the conditional itself.
type ErrorHandler ¶
type ErrorHandler func(http.ResponseWriter, *http.Request, error)
ErrorHandler renders request-time SSR failures.
type GuardRegistry ¶
GuardRegistry resolves guard IDs to executable guard functions.
type LayoutFunc ¶
type LayoutFunc func(LoadContext, string) (string, error)
LayoutFunc wraps already-rendered child HTML with request-aware layout HTML.
type LayoutRegistry ¶
type LayoutRegistry map[string]LayoutFunc
LayoutRegistry maps layout IDs to request-aware layout functions.
type LayoutStack ¶
type LayoutStack []string
LayoutStack is the ordered set of request-time layouts for an SSR page.
type ListField ¶
type ListField struct {
// Placeholder is the unique token inside the template replaced per render.
Placeholder string
// Path is the dotted path to the value (item-relative inside a row, or a
// load field path inside a top-level region). Ignored when Index is true.
Path string
// Index is true when this field substitutes the zero-based row index.
Index bool
}
ListField is one per-row scalar substitution inside a region template.
type ListSpec ¶
type ListSpec struct {
// Placeholder is the unique token embedded in the parent template that the
// rendered rows replace.
Placeholder string
// SourcePath is the dotted path to the slice, resolved against the enclosing
// container (the request-time load data at the top level, or a parent row
// element when nested).
SourcePath string
// RowTemplate is the escaped HTML rendered once per slice element, still
// containing this spec's Field, List, and Cond placeholders.
RowTemplate string
// Fields are the per-row scalar interpolations, each escaped at request time.
Fields []ListField
// Lists are nested g:for lists found inside RowTemplate.
Lists []ListSpec
// Conds are g:if conditionals found inside RowTemplate.
Conds []CondSpec
}
ListSpec describes one server-rendered g:for list. It is generated at build time from a request-time page view and consumed by RenderRegions at request time. A spec is a tree: Lists and Conds describe nested g:for lists and g:if conditionals whose data is resolved relative to each parent row.
type LoadContext ¶
LoadContext is passed to generated request-time load {} functions.
func NewLoadContext ¶
func NewLoadContext(request *http.Request, session map[string]any) LoadContext
NewLoadContext creates the first-slice request context for generated SSR load functions. Session storage is intentionally caller-supplied until the SSR addon defines secure session defaults.
type LoadFunc ¶
type LoadFunc func(LoadContext) (map[string]any, error)
LoadFunc is generated from a request-time load {} block.
type RedirectError ¶
RedirectError asks generated SSR handlers to issue a safe local redirect.
func (RedirectError) Error ¶
func (err RedirectError) Error() string