Skip to content

Runtime helpers reference

This page is the index of every user-facing type and function exported by the gsx runtime package (github.com/gsxhq/gsx). Each entry gives the exact Go signature or type declaration, a one-line description, and a link to the page that shows it in context.

The runtime is standard-library only — no external dependencies. Generated code calls these helpers directly; you call them when you need to box a trusted value, construct an attribute bag in Go code, or implement the Node interface yourself.

Core interface

NameKindSignatureDescription
gsx.NodeinterfaceRender(ctx context.Context, w io.Writer) errorThe rendering interface every gsx component satisfies. Any value implementing this method is renderable in a gsx.Node prop or {children}. See Composition.
gsx.Functypetype Func func(ctx context.Context, w io.Writer) errorAdapts a plain function to gsx.Node; implements Render by calling itself. Useful when writing a one-off Node in Go without declaring a struct. See Raw HTML.

gsx.Node's method set is identical to templ.Component's (as of templ ≥ v0.3), so a gsx.Node satisfies templ.Component structurally and vice-versa — no adapter or import needed.

Trusted-value helpers

These are the explicit opt-outs from gsx's context-aware auto-escaping. Each one vouches that the value is safe for its target context. Do not use them on untrusted input.

NameKindSignature / typeDescription
gsx.Rawfuncfunc Raw(html string) NodeEmits html verbatim — no entity encoding, no escaping. Use only for already-safe HTML (e.g. pre-sanitised Markdown). See Raw HTML.
gsx.RawURLtypetype RawURL stringA URL whose scheme is trusted. In a URL attribute (href, src, etc.) a gsx.RawURL value skips the scheme allow-list check; the string is still attribute-escaped (it cannot break out of quotes). Use as a conversion: gsx.RawURL("app://…"). See Escaping.
gsx.RawJStypetype RawJS stringA JavaScript string the author vouches for. In a <script> body or js`...` interpolation hole, a gsx.RawJS value is emitted verbatim, bypassing JSON-encoding. Use as a conversion around trusted JavaScript only. See JavaScript.
gsx.RawCSStypetype RawCSS stringA CSS value the author vouches for. In a <style> body or style= attribute a gsx.RawCSS value is emitted verbatim, bypassing the CSS value-filter. Use as a conversion: gsx.RawCSS("rgb(0,128,0)"). See Styling.

RawURL, RawJS, and RawCSS are named string types, not functions. Use them as type conversions — gsx.RawJS(expr) — not as function calls.

Attribute bags

NameKindSignature / typeDescription
gsx.Attrstypetype Attrs []AttrOrdered attribute bag — the default bag type. Pairs render in slice order (source order). Used for { bag… } spread and every declared Attrs gsx.Attrs prop. The {{ "k": v }} literal lowers to this type. See Attributes.
gsx.Attrtypetype Attr struct{ Key string; Value any }A single key-value attribute pair. The element type of gsx.Attrs.
gsx.AttrMaptypetype AttrMap map[string]anyOptional map-backed construction helper. Templates accept gsx.Attrs, so call ToAttrs before passing map-shaped data to a bag prop or spread. See Attributes.
gsx.AttrMap.ToAttrsmethodfunc (m AttrMap) ToAttrs() AttrsConverts the map to an ordered Attrs slice with keys sorted ascending for deterministic output. Construct Attrs directly when insertion order matters.

Node boxing

These helpers box ordinary Go values into gsx.Node so they can be passed to a gsx.Node-typed prop.

NameKindSignatureDescription
gsx.Valfuncfunc Val(v any) NodeBoxes any renderable value as a Node. Accepts Node, string, []byte, fmt.Stringer, numeric types, and bool; returns a render-time error (propagated out of Render) for other types. See Props.
gsx.Textfuncfunc Text(s string) NodeBoxes a plain string as an HTML-escaped text Node. Equivalent to { s } inline but usable as a value in Go code.
gsx.Fragmentfuncfunc Fragment(nodes ...Node) NodeGroups multiple Nodes into a single Node that renders them in order with no wrapper element. The value-level equivalent of <> … </>. See Fragments.

Class and style helpers (generated; rarely called directly)

The following helpers are what class={ … } and style={ … } sugar compiles to. You rarely call them by name — the code generator emits them for you. They are documented here for completeness and for authors implementing custom Node types that must participate in the class/style machinery.

NameKindSignatureDescription
gsx.Classfuncfunc Class(s string) ClassPartReturns an always-on class contribution.
gsx.ClassIffuncfunc ClassIf(s string, on bool) ClassPartReturns a conditional class contribution included only when on is true.
gsx.StyleValuefuncfunc StyleValue(v any) stringReturns a CSS-safe string: a gsx.RawCSS value passes through verbatim; any other value is run through the CSS value-filter.

See Styling for the full composable class/style reference.