ssr

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const ImportPath = "github.com/cssbruno/gowdk/addons/ssr"

ImportPath is the canonical Go import path for the SSR addon.

Variables

This section is empty.

Functions

func Addon

func Addon() gowdk.Addon

Addon enables request-time full-page rendering.

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 LoadPath added in v0.1.5

func LoadPath(data map[string]any, path string) (any, bool)

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 added in v0.1.5

func Redirect(url string, status int) error

Redirect returns an error that generated SSR handlers translate into a no-store local redirect with the provided 3xx status.

func RedirectTarget added in v0.1.5

func RedirectTarget(err error) (string, int, bool)

RedirectTarget extracts a generated SSR redirect error.

func RedirectTo added in v0.1.5

func RedirectTo(url string) error

RedirectTo returns an error that generated SSR handlers translate into a no-store local redirect.

func Register

func Register(router Router, routes []Route)

Register adds generated SSR routes to a router.

func RunGuards

func RunGuards(ctx LoadContext, names []string, registry GuardRegistry) error

RunGuards executes guard IDs in declaration order.

Types

type ErrorHandler

type ErrorHandler func(http.ResponseWriter, *http.Request, error)

ErrorHandler renders request-time SSR failures.

type GuardFunc

type GuardFunc func(LoadContext) error

GuardFunc authorizes one request-time SSR page access check.

type GuardRegistry

type GuardRegistry map[string]GuardFunc

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 LoadContext

type LoadContext struct {
	Context context.Context
	Request *http.Request
	Session map[string]any
}

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 added in v0.1.5

type RedirectError struct {
	URL    string
	Status int
}

RedirectError asks generated SSR handlers to issue a safe local redirect.

func (RedirectError) Error added in v0.1.5

func (err RedirectError) Error() string

type Route

type Route struct {
	Pattern string
	Handler http.Handler
}

Route is one generated SSR route binding.

type Router

type Router interface {
	Handle(pattern string, handler http.Handler)
}

Router registers generated SSR page handlers.

Jump to

Keyboard shortcuts

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