Skip to content

Runtime helpers

These are the github.com/gsxhq/gsx types and functions commonly called from application code. See Attributes, Styling, and Escaping for their syntax and safety rules.

Core

NameDeclarationUse
Nodetype Node interface { Render(ctx context.Context, w io.Writer) error }Renderable value returned by every component.
Functype Func func(ctx context.Context, w io.Writer) errorAdapt a render function to Node; its Render method calls the function.

Trusted values

NameDeclarationUse
Rawfunc Raw(html string) NodeRender trusted HTML verbatim.
RawURLtype RawURL stringTrust a URL scheme while retaining attribute escaping.
RawJStype RawJS stringTrust JavaScript and bypass JavaScript encoding.
RawCSStype RawCSS stringTrust CSS and bypass CSS value filtering.

Each entry crosses a trust boundary. Pass only content you control or have validated for that context; see Escaping.

Node values

NameSignatureUse
Valfunc Val(v any) NodeBox a supported Go value as a Node.
Textfunc Text(s string) NodeCreate an HTML-escaped text node.
Fragmentfunc Fragment(nodes ...Node) NodeRender several nodes in order without a wrapper element.

Val accepts nil, Node, []Node, string, []byte, fmt.Stringer, bool, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64. Other values return an error from Render. A named scalar without a supported interface must be converted to its built-in type before boxing it.

Attribute bags

Bag types

NameDeclaration or signatureUse
Attrtype Attr struct { Key string; Value any }One ordered attribute pair.
Attrstype Attrs []AttrOrdered attribute bag.
AttrMap.ToAttrsfunc (m AttrMap) ToAttrs() AttrsConvert a map, sorted by key.

Attrs methods

Read values

NameSignatureUse
Classfunc (a Attrs) Class() stringJoin class values.
Stylefunc (a Attrs) Style() stringJoin style values.
Getfunc (a Attrs) Get(key string) (any, bool)Get the last value.
Hasfunc (a Attrs) Has(key string) boolTest for a key.

Transform bags

NameSignatureUse
Withoutfunc (a Attrs) Without(keys ...string) AttrsCopy without keys.
Takefunc (a Attrs) Take(key string) (any, Attrs)Get and remove a key.
Mergefunc (a Attrs) Merge(other Attrs) AttrsMerge bags; class and style compose.

See Attributes for spread order and Styling for class and style precedence.