Documentation
¶
Overview ¶
Package gx is the runtime of the Gx web framework. It holds the public API for templates, routes, actions, forms and client signals.
Index ¶
- Constants
- Variables
- func Action[In any](fn func(*Ctx, In) error) *action[In]
- func BasePath() string
- func BindSignal(signals map[string]any, scope, name string, dst any) error
- func CSP(opt CSPOptions) func(http.Handler) http.Handler
- func CSRF(next http.Handler) http.Handler
- func Classes(parts ...string) string
- func Collection[Meta any](dir string) *collection[Meta]
- func Cx(parts ...string) string
- func DefaultMessage(key string) string
- func FieldError[T any](field *T, key string) error
- func FieldID(form, path string) string
- func FieldNames(errs map[string]string) []string
- func Forbidden() error
- func Form[In any, P any](fn func(*Ctx, In) error, view func(P) Node) *form[In, P]
- func FormIndexes(r *http.Request, prefix string) []int
- func FormText(r *http.Request, name string) string
- func FragmentID(component, name string, key Key) string
- func IsDev() bool
- func IsIconBody(body string) bool
- func JSON(v any) string
- func Layout[P any](load func(*Ctx) (P, error), view func(P, Node) Node) layout[P]
- func Nav(mode Navigation) navOption
- func Nonce(r *http.Request) string
- func NotFound() error
- func Once[T any](c *Ctx, fn func() (T, error)) (T, error)
- func Page[In any, P any](load func(*Ctx, In) (P, error), view func(P) Node) *page[In, P]
- func Params(fn ParamsFunc) func(http.Handler) http.Handler
- func ParseBool(s string) (bool, error)
- func PathValue(r *http.Request, name string) string
- func Redirect[In interface{ ... }](to In) error
- func RefPath[T any](r SignalRef[T]) string
- func Render(w http.ResponseWriter, r *http.Request, n Node) error
- func RenderNode(w io.Writer, n Node) error
- func RenderRequest(w io.Writer, r *http.Request, n Node) error
- func Scope(r *http.Request) string
- func ScopeString(base string, key Key) string
- func SetAdapter(a Adapter)
- func SetBasePath(path string)
- func SetDev(on bool)
- func SetFrontmatterDecoder(fn func([]byte, any) error)
- func SetGallery(fixtures []Fixture)
- func SetStylesheet(css []byte)
- func SetTranslator(t Translator)
- func SignalJSON(base string, key Key, values map[string]any) string
- func SignalName(base string, key Key, name string) string
- func SignalPath(base string, key Key, name string) string
- func SignalRefPath(base string, key Key, name string) string
- func Signals(r *http.Request) (map[string]any, error)
- func StaticInputs(h Handler) ([]any, bool, error)
- func String(n Node) string
- func StringRequest(r *http.Request, n Node) string
- func Stylesheet() []byte
- func TextValue(v any) string
- func Transition[K any](name string) func(K) TransitionName
- func Translate(key, fallback string) string
- func ValidateURL(action, field string) string
- func ViolationKey(err error) string
- func When(name string, on bool) string
- func WithNonce(r *http.Request, nonce string) *http.Request
- type Adapter
- type App
- type Attr
- type AttrKind
- type Attrs
- type BindError
- type Binder
- type Builder
- type CSPOptions
- type Code
- type Config
- type ContentError
- type ContentPage
- type ContentRoute
- type Ctx
- type ElementPatch
- type Entry
- type Enum
- type FieldView
- type FieldViolation
- type File
- type Fixture
- type Fixtures
- type FormField
- func (f FormField[T]) Attrs() Attrs
- func (f FormField[T]) FieldError() string
- func (f FormField[T]) FieldErrorKey() string
- func (f FormField[T]) FieldHint() string
- func (f FormField[T]) FieldID() string
- func (f FormField[T]) FieldInputType(fallback string) string
- func (f FormField[T]) FieldName() string
- func (f FormField[T]) FieldValidateURL() string
- func (f FormField[T]) FieldValue() string
- type FormInput
- type FormMeta
- type FormProps
- type FormValue
- type Handler
- type HeadProps
- type IconProps
- type Key
- type LLMSEntry
- type LLMSManifest
- type LLMSOptions
- type Link
- type Meta
- type Navigation
- type Node
- func EachRow[T any](rows []T, fn func(int, T) Node) Node
- func El(name string, attrs Attrs, children ...Node) Node
- func FieldErrorNode(fieldID, message string) Node
- func Frag(children ...Node) Node
- func Head(p HeadProps) Node
- func Icon(body string, p IconProps) Node
- func Raw(s SafeHTML) Node
- func RenderToast(r *http.Request, p ToastPatch) Node
- func Text(s string) Node
- func ToastNode(p ToastPatch) Node
- func Toaster() Node
- func Value(v any) Node
- type ParamsFunc
- type Patch
- type PatchMode
- type RedirectPatch
- type Response
- type Route
- type Rule
- func Accept(types ...string) Rule
- func Check(fn func(v any) error) Rule
- func CheckCtx(fn func(ctx context.Context, v any) error) Rule
- func Each(rule Rule) Rule
- func Field[T any](v *T, rules ...Rule) Rule
- func Max(n int64) Rule
- func MaxLen(n int) Rule
- func MaxSize(n int64) Rule
- func Min(n int64) Rule
- func MinLen(n int) Rule
- func OneOf(values ...string) Rule
- func Pattern(re *regexp.Regexp) Rule
- func True(key string) Rule
- type Rules
- type SafeHTML
- type Secret
- type SignalPatch
- type SignalRef
- type Slot
- type Style
- type ToastControl
- type ToastKind
- type ToastOption
- type ToastPatch
- type TransitionName
- type Translator
- type URL
- type Unchecked
Constants ¶
const DefaultThemeCSS = `` /* 5253-byte string literal not displayed */
DefaultThemeCSS is the Tailwind v4 theme file that `gx init` writes to app/theme.css (REQ-STY-03). Token names match shadcn. Dark mode follows a .dark class, and a system preference when no class is set.
const MaxFormRows = 1000
MaxFormRows is the number of rows one repeated form field can hold. A row with a larger index is ignored (REQ-FRM-08).
Variables ¶
var Email = Rule{ // contains filtered or unexported fields }
Email rejects a non-empty string that is not an email address.
var IsURL = Rule{ // contains filtered or unexported fields }
IsURL rejects a non-empty string that is not an http or https URL. It is named IsURL because gx.URL is the typed link value (REQ-RTE-05).
var Required = Rule{ // contains filtered or unexported fields }
Required rejects the zero value of a string, number or bool.
Functions ¶
func Action ¶
Action registers a handler for a route type of any method. The handler answers with Patch, SetSignals, Redirect, Toast or nothing.
func BindSignal ¶
BindSignal fills dst from the named signal inside scope, for example scope "cart.Cart" and name "qty" (REQ-ACT-03). A signal that is not in the request leaves dst unchanged.
func CSP ¶
func CSP(opt CSPOptions) func(http.Handler) http.Handler
CSP is middleware that sets a strict Content-Security-Policy with one fresh nonce per response (SI-11). It works around a whole app, in an app.Group call and around any handler that calls gx.Render.
func CSRF ¶
CSRF protects non-GET requests with Go's cross-origin protection, plus a token for browser-shaped requests that carry no Fetch Metadata (SI-03). gx.App applies it to every route. An action or a form on another router applies the cross-origin protection to itself, so no adoption level needs middleware for it (REQ-RTE-19). The token needs the cookie that this middleware sets, so mount it around another router to protect browsers without Fetch Metadata.
func Classes ¶
Classes joins the non-empty parts with single spaces, in source order (REQ-AUT-10). Resolve conflicts with gx.Cx.
func Collection ¶
Collection declares a content collection rooted at dir, relative to the module root.
func Cx ¶
Cx merges class strings with the semantics of tailwind-merge for Tailwind v4 (REQ-STY-04). A later class removes an earlier class of the same class group or of a group that conflicts with it. A modifier scopes the conflict. The classes that stay keep their order, and a class that Tailwind does not know stays.
The class groups come from the tailwind-merge default configuration: the table in cxtable.go is generated from it, and the functions below are a port of its merge, parse and validator code.
func DefaultMessage ¶
DefaultMessage returns the English message of a built-in rule key, or the key itself when the key has no default (REQ-FRM-10).
func FieldError ¶
FieldError re-renders the form with key as the error of one input field (REQ-FRM-02). The field pointer names the field through the generated GxFieldName method.
func FieldID ¶
FieldID returns the element id of one form field, for example ("signup", "addresses[0].street") gives "signup-addresses-0-street" (REQ-FRM-03).
func FieldNames ¶
FieldNames returns the sorted field names of a field error map.
func Form ¶
Form registers a form action for a route type (REQ-FRM-02). In is a pointer to the route input type:
gx.Form(func(c *gx.Ctx, in *Signup) error { ... }, SignupView)
The view renders the page that holds the form. An invalid submit answers the full view with 422; with an adapter only the form element is patched (REQ-FRM-05).
func FormIndexes ¶
FormIndexes returns the sorted row indexes present for an indexed form name, for example 0 and 2 for addresses[0].street and addresses[2].city (REQ-FRM-08).
func FragmentID ¶
FragmentID returns the id of one fragment instance: component-scoped, and keyed when the instance has a key (REQ-AUT-13).
func IsIconBody ¶
IsIconBody reports whether a string looks like the inner markup of an icon. The icon generator refuses anything else, so a generated icon cannot carry markup that breaks out of the svg.
func JSON ¶
JSON returns the JSON form of a server value inlined into a client expression (SI-05). It panics when the value has no JSON form: the compiler must not inline it.
func Layout ¶
Layout builds a layout from an optional loader and a view that takes the loaded props and the page node (REQ-RTE-08). Pass a nil load when the layout needs no data.
func Nav ¶
func Nav(mode Navigation) navOption
Nav sets the navigation mode of the routes that follow it in a Group (REQ-RTE-12).
func Nonce ¶
Nonce returns the CSP nonce of the request, or "" when no policy set one. A page author needs it only for a script inside trusted raw HTML.
func Once ¶
Once runs fn once per request and returns its value (REQ-RTE-08). It keys on the call site, so share one call site or extract a helper.
func Page ¶
Page builds a typed page from a loader and a view. The route input type In carries the pattern and the generated Bind method.
func Params ¶
func Params(fn ParamsFunc) func(http.Handler) http.Handler
Params returns middleware that installs a path variable reader for routers that do not fill r.PathValue (REQ-RTE-17).
func ParseBool ¶
ParseBool parses an HTML form boolean. "on" is the value of a checked checkbox without a value attribute.
func PathValue ¶
PathValue reads a path variable through the Params reader, or through r.PathValue when no reader is set.
func RefPath ¶
RefPath returns the adapter reference of a signal ref, with the leading $, so a child can share a parent signal.
func Render ¶
Render renders n inside any http.Handler (REQ-RTE-16). It sets the content type, marks active links for r and writes the merged head.
func RenderNode ¶
RenderNode writes n to a writer with no request in scope.
func RenderRequest ¶
RenderRequest renders n with the request in scope, so typed links mark the active page (REQ-RTE-13). The rendered markers feed the runtime script decision of the app (NFR-04).
func Scope ¶
Scope returns the signal scope of the invoking component instance, or "" (REQ-ACT-06).
func ScopeString ¶
ScopeString returns the signal namespace of a component instance: the component path plus its key (REQ-ACT-06).
func SetAdapter ¶
func SetAdapter(a Adapter)
SetAdapter sets the adapter of the process. New does this from Config.Adapter. Actions mounted outside a gx.App use the default.
func SetBasePath ¶
func SetBasePath(path string)
SetBasePath sets the prefix of generated links (REQ-RTE-18).
func SetDev ¶
func SetDev(on bool)
SetDev turns the dev checks on or off. gx dev sets it (REQ-DEV-01).
func SetFrontmatterDecoder ¶
SetFrontmatterDecoder installs the frontmatter decoder of the process (REQ-CNT-02). The gx/content package installs one.
func SetGallery ¶
func SetGallery(fixtures []Fixture)
SetGallery installs the fixture list of the dev gallery (REQ-AI-03). The generated gxdev_gallery package supplies it; the scaffold's main calls this with gxdev.
func SetTranslator ¶
func SetTranslator(t Translator)
SetTranslator sets the message translator of the process (REQ-FRM-10).
func SignalJSON ¶
SignalJSON renders the data-signals JSON of one component instance from the initial values of its signals (REQ-ACT-05).
func SignalName ¶
SignalName returns the dotted name of one signal, as data-bind takes it (REQ-ACT-07), for example cart.Cart.42.qty.
func SignalPath ¶
SignalPath returns the adapter signal reference of one signal in one component instance, for example $["cart"]["Cart"]["42"]["qty"] (REQ-ACT-07).
func SignalRefPath ¶
SignalRefPath returns the bracket path of one signal, without the leading $, for example ["cart"]["Cart"]["42"]["qty"].
func Signals ¶
Signals decodes the request signals through the app adapter (REQ-ACT-03). It returns nil when no adapter is set.
func StaticInputs ¶
StaticInputs reports the export inputs of a route, when it lists any.
func StringRequest ¶
StringRequest returns the HTML of n with the request in scope.
func Transition ¶
func Transition[K any](name string) func(K) TransitionName
Transition returns a typed transition. Call it with a key to pair one element across two pages:
var ProductImage = gx.Transition[int64]("product-image")
<img transition={ProductImage(p.Product.ID)} src=... />
func Translate ¶
Translate returns the message of key. Without a translator it returns fallback, the English default (REQ-FRM-10).
func ValidateURL ¶
ValidateURL returns the live validation URL of one field (REQ-FRM-06).
func ViolationKey ¶
ViolationKey returns the message key of a field violation, or "invalid" (REQ-FRM-09).
Types ¶
type Adapter ¶
type Adapter interface {
// Name identifies the adapter, for example "datastar".
Name() string
// Signals reports whether the adapter supports client signals and
// client expressions (REQ-ACT-09).
Signals() bool
// Runtime returns the script nodes every page needs (request
// lifecycle step 6), or nil.
Runtime() Node
// Assets returns static files keyed by their name below /_gx/.
Assets() map[string][]byte
// Respond writes the commands of an action or a navigation.
Respond(w http.ResponseWriter, r *http.Request, res *Response) error
// ReadSignals decodes the request signals into dst, a pointer.
ReadSignals(r *http.Request, dst any) error
// Invoke returns the attribute that makes an element invoke the
// action at url with the HTTP method on its click (REQ-ACT-02). A
// non-empty scope names the invoking component instance
// (REQ-ACT-03). It returns the zero Attr for a method the client
// cannot invoke.
Invoke(method, url, scope string) Attr
}
Adapter is the public hook between Gx and one hypermedia library (REQ-PLG-04). One adapter serves one app (P2).
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is an http.Handler that owns a ServeMux (REQ-RTE-18).
type Attr ¶
Attr is one attribute of an element. Active marks a typed link for the aria-current and data-active rules of REQ-RTE-13: "page" (exact match) or "section" (path prefix).
func Invoke ¶
Invoke returns the attribute that invokes the action at url with the HTTP method (REQ-ACT-02). A non-empty scope names the invoking component instance (REQ-ACT-03). Generated code puts the Value in the attribute of an on: handler. The adapter of the request, or the process default, writes the attribute when the node renders.
type Attrs ¶
type Attrs []Attr
Attrs is an ordered attribute list.
func FieldControlAttrs ¶
FieldControlAttrs returns the control attributes of one field with extra aria-describedby ids, for example a hint element (REQ-FRM-11).
func ToastAttrs ¶
func ToastAttrs(p ToastPatch) Attrs
ToastAttrs returns the attributes the root element of a toast carries: the contract between the markup and the behaviour runtime (REQ-REG-11). A component that renders a toast spreads them on its root element.
type BindError ¶
type BindError struct {
Err error
}
BindError marks a request whose input did not bind; the page answers 400.
type Binder ¶
Binder is the generated route interface: a pattern and request binding. The gx generator writes Pattern and Bind.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder collects nodes while a generated component runs.
type CSPOptions ¶
type CSPOptions struct {
// UnsafeEval adds 'unsafe-eval' to script-src. The Datastar adapter
// needs it: Datastar evaluates client expressions at runtime.
UnsafeEval bool
// Directives holds more directives, for example
// "img-src 'self' data:; frame-ancestors 'none'".
Directives string
}
CSPOptions configure gx.CSP.
type Code ¶
type Code struct {
// File is the module-relative path of the source file.
File string
// Lang is the chroma lexer name; empty guesses from File.
Lang string
// Source is the selected source text with a trailing newline.
Source string
}
Code is one code block of the docs kit (REQ-CNT-05). The compiler fills it from gx.CodeFile at build time and fails the build when the file or a selected line is missing.
type Config ¶
type Config struct {
BasePath string
Adapter Adapter
// Toast renders one toast (REQ-REG-11). An app sets it to the Render
// function of its installed toast item, so the toast markup and its
// classes stay in app-owned source. Without it a toast is the plain
// ToastNode.
Toast func(ToastPatch) Node
// Public holds the app's own static files, for example an embedded
// public directory. A GET for a path that names a file in it answers
// that file before any route, so the binary needs no file beside it
// (NFR-08).
Public fs.FS
}
Config holds app options. BasePath prefixes every generated link, and Adapter selects the hypermedia library (REQ-RTE-18, REQ-ACT-09). Package gx exports only the standard library plus an optional adapter runtime dependency.
type ContentError ¶
ContentError is a frontmatter or rule error of one content file (REQ-CNT-02).
func (*ContentError) Error ¶
func (e *ContentError) Error() string
type ContentPage ¶
type ContentPage struct {
Slug string `path:"slug"`
// contains filtered or unexported fields
}
ContentPage is the export input of one content page (REQ-CNT-02).
func (ContentPage) URL ¶
func (p ContentPage) URL() string
URL implements the typed link value of a content page (REQ-EXP-01). The index entry is the root of the collection.
type ContentRoute ¶
type ContentRoute[Meta any] struct { // contains filtered or unexported fields }
ContentRoute serves one content collection (REQ-CNT-02) and carries the configuration of the llms.txt export (REQ-CNT-08).
func ContentEntries ¶
func ContentEntries[Meta any](c *collection[Meta], view func(Entry[Meta]) Node) *ContentRoute[Meta]
ContentEntries makes one route per entry and passes the whole Entry to view (REQ-CNT-06). The docs shell needs the slug to build links, the table of contents and the previous and next pages.
func ContentPages ¶
func ContentPages[Meta any](c *collection[Meta], view func(Meta, []byte) Node) *ContentRoute[Meta]
ContentPages makes the content route of the collection (REQ-CNT-02): one URL per entry under "/{slug...}". view builds the page from the typed frontmatter and the raw Markdown body; the docs kit renders the body.
func (*ContentRoute[Meta]) LLMS ¶
func (h *ContentRoute[Meta]) LLMS(opt LLMSOptions[Meta]) *ContentRoute[Meta]
LLMS configures the llms.txt files of this collection (REQ-CNT-08).
func (*ContentRoute[Meta]) Pattern ¶
func (h *ContentRoute[Meta]) Pattern() string
Pattern implements Handler (REQ-CNT-02). The trailing wildcard serves a nested entry slug ("guides/routing") as one path.
func (*ContentRoute[Meta]) ServeHTTP ¶
func (h *ContentRoute[Meta]) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP renders the entry named by the path value. The empty slug is the collection index (REQ-CNT-06).
type Ctx ¶
type Ctx struct {
W http.ResponseWriter
R *http.Request
// contains filtered or unexported fields
}
Ctx is the per-request context (REQ-RTE-01).
func (*Ctx) SetSignals ¶
SetSignals updates the signals of the invoking component instance (REQ-ACT-05).
type ElementPatch ¶
ElementPatch changes one element, named by Target, a CSS selector.
type Entry ¶
type Entry[Meta any] struct { // Slug is the path below the collection directory without ".md". Slug string // File is the absolute path of the file. File string // Meta is the decoded frontmatter. Meta Meta // Body is the Markdown without the frontmatter. Body []byte }
Entry is one loaded content page (REQ-CNT-02).
type Enum ¶
type Enum[T comparable] map[T]string
Enum[T] is a class map for the constants of T. The analyzer requires an entry for every constant of T (REQ-STY-05).
type FieldView ¶
type FieldView interface {
Attrs() Attrs
FieldName() string
FieldID() string
FieldValue() string
FieldError() string
FieldErrorKey() string
FieldValidateURL() string
// FieldInputType returns the rule-derived input type ("email", "url"),
// or fallback (REQ-FRM-04).
FieldInputType(fallback string) string
// FieldHint returns the helper text, or "".
FieldHint() string
}
FieldView is the non-generic view of a field, for field components that serve every field type (REQ-FRM-03).
type FieldViolation ¶
FieldViolation is one failed field rule (REQ-FRM-02, SI-13).
func RunAllRulesContext ¶
func RunAllRulesContext(ctx context.Context, v any) []*FieldViolation
RunAllRulesContext runs every field rule and returns one failure per failing field, in rule order (REQ-FRM-02). The form handler shows the whole error list.
func RunRules ¶
func RunRules(v any) *FieldViolation
RunRules runs the Rules of an input value and returns the first failure (SI-13).
func RunRulesContext ¶
func RunRulesContext(ctx context.Context, v any) *FieldViolation
RunRulesContext is RunRules with a request context for CheckCtx.
func (*FieldViolation) Error ¶
func (e *FieldViolation) Error() string
type File ¶
type File struct {
// Name is the client file name.
Name string
// Size is the number of bytes stored.
Size int64
// Type is the content type, for example "image/png".
Type string
// Temp is the path of the temp file.
Temp string
}
File is one uploaded file (REQ-FRM-09). The upload streams to a temp file during binding; the framework removes it after the handler returns.
func ReadUploads ¶
ReadUploads streams every part of one form name to a temp file and enforces the size and type limits before the handler runs (REQ-FRM-09).
type Fixture ¶
type Fixture struct {
Component string
// Package is the import path of the component, for the dev gallery.
Package string
Name string
Node func() Node
Missing bool
}
Fixture is one gallery entry. A component without a fixtures file has Missing set and no Node.
type Fixtures ¶
Fixtures names example prop sets for the dev gallery (REQ-AI-03). A file <Name>.fixtures.go declares one:
var Fixtures = gx.Fixtures[CardProps]{
"Default": {Title: "Card"},
}
type FormField ¶
type FormField[T any] struct { // Name is the form field name, for example "email". Name string // ID is the control id, for example "signup-email". ID string // Value is the bound value. Value T // Error is the translated error message, or "". Error string // ErrorKey is the stable message key of Error, for example "required". ErrorKey string // Constraints holds the native constraints of the rules // (REQ-FRM-04). Constraints Attrs // ValidateURL is the URL of the live validation action (REQ-FRM-06). ValidateURL string // Hint is the helper text of the control, or "". Hint string }
Field is one generated form control (REQ-FRM-03). The compiler writes the static parts; the form handler writes Error and ErrorKey.
func (FormField[T]) Attrs ¶
Attrs returns the control attributes: name, id, value, native constraints and the aria state (REQ-FRM-03, REQ-FRM-11).
func (FormField[T]) FieldError ¶
FieldError implements FieldView.
func (FormField[T]) FieldErrorKey ¶
FieldErrorKey implements FieldView.
func (FormField[T]) FieldInputType ¶
FieldInputType implements FieldView.
func (FormField[T]) FieldValidateURL ¶
FieldValidateURL implements FieldView.
func (FormField[T]) FieldValue ¶
FieldValue implements FieldView.
type FormInput ¶
type FormInput interface {
Pattern() string
// GxNewForm returns a fresh input value.
GxNewForm() FormInput
GxBindForm(*http.Request) (map[string]string, error)
Rules() Rules
GxFormValue(map[string]string) FormValue
GxFieldName(any) string
// GxRunForm calls the user handler with the concrete input type.
GxRunForm(*Ctx, any) error
}
FormInput is the generated interface of a form input type (REQ-FRM-02).
type FormMeta ¶
type FormMeta struct {
// Name is the input type in lower-first form, for example "signup".
Name string
// ID is the id of the form element, for example "signup-form".
ID string
// Action is the form action URL, from the route pattern.
Action string
// Method is the HTTP method, for example "POST".
Method string
// Enctype is the form encoding when the form holds files
// (REQ-FRM-09).
Enctype string
}
FormMeta is the generated form element state of an input type (REQ-FRM-03). The compiler embeds it in every <Type>Form value.
func (FormMeta) Attrs ¶
Attrs returns the attributes of the form element. The client runtime submits every form marked with data-gx-form through the adapter (REQ-FRM-05).
func (FormMeta) GxFormAction ¶
GxFormAction implements FormValue.
func (FormMeta) GxFormMethod ¶
GxFormMethod implements FormValue.
func (FormMeta) GxFormName ¶
GxFormName implements FormValue.
type FormProps ¶
type FormProps interface {
GxSetForm(FormValue)
}
FormProps is implemented by a generated view props struct that holds a form value (REQ-FRM-03). The generated GxSetForm fills that field.
type FormValue ¶
type FormValue interface {
GxFormName() string
GxFormID() string
GxFormAction() string
GxFormMethod() string
}
FormValue is implemented by every generated <Type>Form (REQ-FRM-03).
type HeadProps ¶
type HeadProps struct {
Title string `json:"title,omitempty"`
Meta []Meta `json:"meta,omitempty"`
Links []Link `json:"links,omitempty"`
// Lang, HtmlClass and BodyClass set attributes of the document shell.
// The deepest value wins; Lang defaults to "en".
Lang string `json:"lang,omitempty"`
HtmlClass string `json:"htmlClass,omitempty"`
BodyClass string `json:"bodyClass,omitempty"`
}
HeadProps is the props of the gx.Head component.
type IconProps ¶
type IconProps struct {
// Label sets role="img" and aria-label. Without it the icon is
// decorative: aria-hidden="true".
Label string
// Class is the class attribute of the svg.
Class string
// Attrs adds extra attributes.
Attrs Attrs
}
IconProps are the props of a generated icon component (REQ-STY-06).
type Key ¶
type Key string
Key identifies one component instance (REQ-ACT-06).
func ChildKey ¶
ChildKey returns the key of an unkeyed call site under parent. The same call site gives the same key on every render (REQ-ACT-06).
func InstanceKey ¶
InstanceKey returns the key of a component call site from its key expression.
type LLMSEntry ¶
type LLMSEntry struct {
Path string `json:"path"`
Title string `json:"title"`
Description string `json:"description"`
Body string `json:"body"`
Skip bool `json:"skip"`
}
LLMSEntry is one page of the llms.txt export (REQ-CNT-08).
type LLMSManifest ¶
type LLMSManifest struct {
Site string `json:"site"`
Summary string `json:"summary"`
Entries []LLMSEntry `json:"entries"`
}
LLMSManifest is the llms.txt data of one content route (REQ-CNT-08). The dev-only export manifest carries it to the exporter.
type LLMSOptions ¶
type LLMSOptions[Meta any] struct { // Site is the H1 of llms.txt. Site string // Summary is the blockquote line of llms.txt. Summary string // Title returns the entry title. Title func(Meta) string // Description returns the entry description. Description func(Meta) string // Skip keeps the entry out of the llms files when it returns true. Skip func(Meta) bool }
LLMSOptions configure the llms.txt export of one content route (REQ-CNT-08).
type Meta ¶
type Meta struct {
Name string `json:"name,omitempty"`
Property string `json:"property,omitempty"`
Content string `json:"content,omitempty"`
}
Meta is one meta tag in the head (REQ-RTE-11).
type Navigation ¶
type Navigation uint8
Navigation selects how a link between two pages with a shared layout loads (REQ-RTE-12).
const ( FullNavigation Navigation = iota MorphNavigation )
type Node ¶
type Node interface {
// contains filtered or unexported methods
}
Node is one node of a render tree. Only this package implements Node.
var Append Node = patchModeNode{ModeAppend}
Append sends the following patches with append mode.
var Prepend Node = patchModeNode{ModePrepend}
Prepend sends the following patches with prepend mode.
var Remove Node = patchModeNode{ModeRemove}
Remove sends the following patches with remove mode.
var Replace Node = patchModeNode{ModeReplace}
Replace sends the following patches with replace mode.
var ViewTransition Node = transitionNode{}
ViewTransition wraps the following patches in startViewTransition (REQ-ACT-12).
func El ¶
El returns an element node. An empty attribute value means a boolean attribute; AttrBool with the value "false" is omitted.
func FieldErrorNode ¶
FieldErrorNode renders the error element of one field (REQ-FRM-11). Field components render the same element so a live validation patch morphs it.
func Head ¶
Head marks the head of a page or layout. The deepest title wins and the other tags merge.
func Icon ¶
Icon renders one icon as an inline svg with currentColor. body is the inner markup of a pinned icon pack, not user input.
func Raw ¶
Raw returns a node that writes s without escaping. Use it only for gx.SafeHTML values (SI-01).
func RenderToast ¶
func RenderToast(r *http.Request, p ToastPatch) Node
RenderToast renders one toast for an adapter: with Config.Toast of the app that serves the request, or as ToastNode when the app sets none.
func ToastNode ¶
func ToastNode(p ToastPatch) Node
ToastNode is the plain markup of one toast. An app that sets Config.Toast renders its own component instead.
type ParamsFunc ¶
ParamsFunc reads a path variable from a request (REQ-RTE-17).
type Patch ¶
type Patch interface {
// contains filtered or unexported methods
}
Patch is one change an adapter sends to the client (REQ-ACT-04).
type PatchMode ¶
type PatchMode uint8
PatchMode selects how an element patch reaches the DOM.
const ( // ModeMorph morphs the node into the existing element. It is the // default. ModeMorph PatchMode = iota // ModeInner replaces the children of the existing element. ModeInner // ModeAppend puts the node inside the existing element, at the end. ModeAppend // ModePrepend puts the node inside the existing element, at the start. ModePrepend // ModeReplace replaces the existing element with the node. ModeReplace // ModeRemove removes the existing element. ModeRemove )
type RedirectPatch ¶
type RedirectPatch struct{ URL string }
RedirectPatch navigates the client to URL.
type Response ¶
type Response struct {
Patches []Patch
// Status is the HTTP status to answer with, or 0 for the default.
Status int
// Err is the handler error, shown by the dev overlay (REQ-DEV-06).
Err error
Navigate bool
// Head is the merged head of a partial navigation (REQ-RTE-12).
Head *HeadProps
}
Response is the ordered answer of an action, a form or a navigation.
type Route ¶
type Route struct{}
Route is embedded in a route input struct. The tag carries the method and the pattern: "GET /products/{id}" (REQ-RTE-01).
type Rule ¶
type Rule struct {
// contains filtered or unexported fields
}
Rule checks one input value (REQ-FRM-01). Every built-in rule leaves the zero value alone; Required rejects it.
type Secret ¶
type Secret string
Secret is a value that must not leave the server (SI-04). It renders and marshals as "[redacted]".
func (Secret) MarshalJSON ¶
MarshalJSON never writes the secret.
type SignalPatch ¶
SignalPatch sets the signals of one component scope (REQ-ACT-05).
type SignalRef ¶
SignalRef is a prop that carries a parent signal reference into a child component (REQ-ACT-07).
type Style ¶
type Style string
Style is a dynamic style attribute value.
func TransitionStyle ¶
func TransitionStyle(t TransitionName) Style
TransitionStyle renders the sanitized view-transition-name and view-transition-class of a transition (REQ-STY-07).
type ToastControl ¶
type ToastControl struct {
Label string
URL URL
// Method is the HTTP method of the action. It is empty for a link.
Method string
}
ToastControl is the one control of a toast: a link to URL, or a button that invokes the action at URL.
type ToastKind ¶
type ToastKind uint8
ToastKind is the kind of one toast (REQ-REG-11). A kind is also a ToastOption, so an action passes it directly: c.Toast("Saved", gx.ToastSuccess).
const ( // ToastDefault is a neutral message with no icon. ToastDefault ToastKind = iota // ToastSuccess reports a finished operation. ToastSuccess // ToastInfo gives neutral information. ToastInfo // ToastWarning reports a result the user must check. ToastWarning // ToastError reports a failure. It renders as role="alert". ToastError // ToastLoading reports running work. It stays until a later toast with // the same ID replaces it, or the user closes it. ToastLoading )
type ToastOption ¶
type ToastOption interface {
// contains filtered or unexported methods
}
ToastOption sets one field of a toast (REQ-REG-11).
var ToastSticky ToastOption = toastOptionFunc(func(p *ToastPatch) { p.Sticky = true })
ToastSticky keeps the toast until the user closes it.
func ToastAction ¶
func ToastAction[In interface {
Pattern() string
URL() string
}](label string, in In) ToastOption
ToastAction adds one button that invokes the action of a route value, for example Undo (REQ-ACT-02). The toast closes when the user presses the button. A toast holds one control: of ToastLink and ToastAction, the later option wins.
func ToastDescription ¶
func ToastDescription(text string) ToastOption
ToastDescription adds a second line below the text.
func ToastDuration ¶
func ToastDuration(d time.Duration) ToastOption
ToastDuration sets how long the toast stays. The default is 4 seconds.
func ToastID ¶
func ToastID(id string) ToastOption
ToastID names the toast. A later toast with the same ID replaces the earlier one in place, so a handler can show loading and then success.
func ToastLink ¶
func ToastLink(label string, to interface{ URL() string }) ToastOption
ToastLink adds one link that navigates to a route value. A toast holds one control: of ToastLink and ToastAction, the later option wins.
type ToastPatch ¶
type ToastPatch struct {
Text string
Kind ToastKind
Description string
// ID makes a later toast with the same ID replace this one in place.
ID string
// Duration is the time before the toast leaves, or 0 for the default.
Duration time.Duration
// Sticky keeps the toast until the user closes it.
Sticky bool
// Action is the control: a link or an action button. The zero value
// renders none.
Action ToastControl
}
ToastPatch adds one toast to the toaster region (REQ-REG-11).
func (ToastPatch) Timeout ¶
func (p ToastPatch) Timeout() time.Duration
Timeout returns the time before the toast leaves on its own. It is 0 for a sticky toast and for a loading toast: they never leave on their own.
type TransitionName ¶
TransitionName is the rendered value of a typed transition (REQ-STY-07).
type Translator ¶
Translator turns a message key into a message (REQ-FRM-10). fallback is the English message of the key.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
adapters
|
|
|
datastar
Package datastar adapts Gx to the Datastar hypermedia library through the public gx.Adapter hook (REQ-PLG-04, DR-04).
|
Package datastar adapts Gx to the Datastar hypermedia library through the public gx.Adapter hook (REQ-PLG-04, DR-04). |
|
cmd
|
|
|
gx
command
Command gx is the Gx command line tool.
|
Command gx is the Gx command line tool. |
|
Package content renders Markdown bodies for content pages (REQ-CNT-02) and code frames for the docs kit (REQ-CNT-05).
|
Package content renders Markdown bodies for content pages (REQ-CNT-02) and code frames for the docs kit (REQ-CNT-05). |
|
Package gxc holds typed helpers that a client expression can call.
|
Package gxc holds typed helpers that a client expression can call. |
|
Package gxcli implements the gx command line tool.
|
Package gxcli implements the gx command line tool. |
|
internal
|
|
|
analyze
Package analyze holds the Gx go/analysis passes: route packages (GX3005) and safe HTML conversions (GX7001).
|
Package analyze holds the Gx go/analysis passes: route packages (GX3005) and safe HTML conversions (GX7001). |
|
appmodel
Package appmodel builds the full model of an app (REQ-AI-01): the model the compiler reads from the code, plus the icon sets and the registry items of gx.lock.
|
Package appmodel builds the full model of an app (REQ-AI-01): the model the compiler reads from the code, plus the icon sets and the registry items of gx.lock. |
|
apprun
Package apprun builds an app with the gxdev tag and runs it on a free local port.
|
Package apprun builds an app with the gxdev tag and runs it on a free local port. |
|
bench
templ: version: v0.3.1020
|
templ: version: v0.3.1020 |
|
build/devgif
command
Command devgif records the dev loop of a new app as an animated GIF for the README (REQ-DOC-05).
|
Command devgif records the dev loop of a new app as an animated GIF for the README (REQ-DOC-05). |
|
build/evidence
command
Command evidence writes and checks docs/build/evidence.json.
|
Command evidence writes and checks docs/build/evidence.json. |
|
compiler
Package compiler parses .gx files into an AST.
|
Package compiler parses .gx files into an AST. |
|
content
Package content renders Markdown at build time: CommonMark plus the GFM extensions, stable heading ids and anchor links, and the GFM disallowed raw HTML filter (REQ-CNT-01).
|
Package content renders Markdown at build time: CommonMark plus the GFM extensions, stable heading ids and anchor links, and the GFM disallowed raw HTML filter (REQ-CNT-01). |
|
devserver
Package devserver is the `gx dev` loop: build, run, watch, reload (REQ-DEV-01, REQ-DEV-03, REQ-DEV-06, REQ-DEV-07).
|
Package devserver is the `gx dev` loop: build, run, watch, reload (REQ-DEV-01, REQ-DEV-03, REQ-DEV-06, REQ-DEV-07). |
|
docscheck
Package docscheck reads the pages of the docs site for the tests that keep them true: the diagnostic pages (REQ-DOC-03), the code samples (REQ-DOC-04) and the page inventory (REQ-DOC-02).
|
Package docscheck reads the pages of the docs site for the tests that keep them true: the diagnostic pages (REQ-DOC-03), the code samples (REQ-DOC-04) and the page inventory (REQ-DOC-02). |
|
docsgen
command
Command docsgen writes the component pages of the docs site from the registry (REQ-DOC-02).
|
Command docsgen writes the component pages of the docs site from the registry (REQ-DOC-02). |
|
editors
Package editors holds the checks for the editor integrations (REQ-TLS-05, REQ-TLS-06).
|
Package editors holds the checks for the editor integrations (REQ-TLS-05, REQ-TLS-06). |
|
execname
Package execname names a built binary for the host platform.
|
Package execname names a built binary for the host platform. |
|
exporter
Package exporter renders a Gx app to static files (REQ-EXP-01).
|
Package exporter renders a Gx app to static files (REQ-EXP-01). |
|
goload
Package goload loads the Go packages of an app for the compiler and the analyzers.
|
Package goload loads the Go packages of an app for the compiler and the analyzers. |
|
gxconfig
Package gxconfig reads the hand-written gx.toml of an app.
|
Package gxconfig reads the hand-written gx.toml of an app. |
|
gxstyles
Package gxstyles writes the generated package that embeds the built stylesheet (REQ-STY-02).
|
Package gxstyles writes the generated package that embeds the built stylesheet (REQ-STY-02). |
|
highlight
Package highlight renders syntax-highlighted code frames (REQ-CNT-04).
|
Package highlight renders syntax-highlighted code frames (REQ-CNT-04). |
|
icons
Package icons pins an icon set and generates one .gx component per icon (REQ-STY-06).
|
Package icons pins an icon set and generates one .gx component per icon (REQ-STY-06). |
|
images
Package images reads and resizes PNG and JPEG content images in pure Go (REQ-CNT-11).
|
Package images reads and resizes PNG and JPEG content images in pure Go (REQ-CNT-11). |
|
lsp
Package lsp implements the gx language server over base LSP on stdio (REQ-DEV-08, REQ-TLS-04).
|
Package lsp implements the gx language server over base LSP on stdio (REQ-DEV-08, REQ-TLS-04). |
|
mcpserver
Package mcpserver is the dev MCP server of `gx mcp` (REQ-AI-04).
|
Package mcpserver is the dev MCP server of `gx mcp` (REQ-AI-04). |
|
pagefind
Package pagefind manages the pinned Pagefind standalone binary (REQ-CNT-07).
|
Package pagefind manages the pinned Pagefind standalone binary (REQ-CNT-07). |
|
refcss
command
Command refcss builds the dev-only reference stylesheet of the visual parity suite (REQ-REG-08) with the pinned Tailwind binary.
|
Command refcss builds the dev-only reference stylesheet of the visual parity suite (REQ-REG-08) with the pinned Tailwind binary. |
|
registry
Package registry is the Gx component registry format (REQ-REG-01).
|
Package registry is the Gx component registry format (REQ-REG-01). |
|
ruleiter
Package ruleiter iterates slice values for the rule engine.
|
Package ruleiter iterates slice values for the rule engine. |
|
scaffold
Package scaffold writes new Gx apps and new typed code into an app (REQ-DEV-10): `gx init`, `gx new` and the managed section of AGENTS.md (REQ-AI-05).
|
Package scaffold writes new Gx apps and new typed code into an app (REQ-DEV-10): `gx init`, `gx new` and the managed section of AGENTS.md (REQ-AI-05). |
|
stelint
Package stelint checks prose against the rules of ASD-STE100 that a program can decide (NFR-10): short sentences, short paragraphs, no contraction, no future tense, the active voice in a procedure step, and no word from the list of words that Simplified Technical English does not approve.
|
Package stelint checks prose against the rules of ASD-STE100 that a program can decide (NFR-10): short sentences, short paragraphs, no contraction, no future tense, the active voice in a procedure step, and no word from the list of words that Simplified Technical English does not approve. |
|
stelint/cmd/stelint
command
Command stelint checks Markdown files against the rules of ASD-STE100 that a program can decide (NFR-10).
|
Command stelint checks Markdown files against the rules of ASD-STE100 that a program can decide (NFR-10). |
|
tailwind
Package tailwind manages the pinned Tailwind CSS standalone binary (REQ-STY-01).
|
Package tailwind manages the pinned Tailwind CSS standalone binary (REQ-STY-01). |
|
testbudget
Package testbudget scales the NFR time budgets to the machine that runs the test.
|
Package testbudget scales the NFR time budgets to the machine that runs the test. |
|
Package lintplugin registers the Gx analyzers with golangci-lint through the module plugin system (REQ-TLS-03).
|
Package lintplugin registers the Gx analyzers with golangci-lint through the module plugin system (REQ-TLS-03). |
|
registry
|
|
|
data-table
Package datatable renders a server-driven table (REQ-REG-10).
|
Package datatable renders a server-driven table (REQ-REG-10). |
|
docs-shell
Package shell is the docs-shell registry block (REQ-CNT-06): a layout with a header, a sidebar, a table of contents, pagination and a 404, plus the client behaviours they need.
|
Package shell is the docs-shell registry block (REQ-CNT-06): a layout with a header, a sidebar, a table of contents, pagination and a 404, plus the client behaviours they need. |
|
tests
|
|
|
review/round-1/adminui
Package adminui holds the layout of one slice for the round-1 review test TestREQ_RTE_12_LayoutsWithTheSameFileNameAndLine.
|
Package adminui holds the layout of one slice for the round-1 review test TestREQ_RTE_12_LayoutsWithTheSameFileNameAndLine. |
|
review/round-1/shopui
Package shopui holds the layout of one slice for the round-1 review test TestREQ_RTE_12_LayoutsWithTheSameFileNameAndLine.
|
Package shopui holds the layout of one slice for the round-1 review test TestREQ_RTE_12_LayoutsWithTheSameFileNameAndLine. |
