Skip to content

Go API

Full generated documentation is on pkg.go.dev. This page is the map: what exists, and why.

import alacris "github.com/bmartel/alacris-go"
E(tag string) *ElementStart an element. An invalid custom element name is recorded as an error.
(*Element) Prop(name string, v any)Set a component prop, encoded from its Go type. nil omits it.
(*Element) PropRaw(name, value string)Set an already-encoded prop value.
(*Element) Props(map[string]any)Several props, applied in sorted key order.
(*Element) Attr(name string, v any)An ordinary HTML attribute; a false bool disappears.
(*Element) Attrs(templ.Attributes)Spread an attribute map.
(*Element) ID(string)Set id. Required for anything the live layer patches.
(*Element) Class(...string) / ClassIf(bool, ...string)Append class names.
(*Element) Style(property, value string)One sanitized inline declaration.
(*Element) Var(name, value string)A CSS custom property; -- optional.
(*Element) Vars(map[string]string)Several custom properties.
(*Element) Apply(VarSet, map[string]string)Custom properties checked against a contract.
(*Element) On(event, action string)Forward a CustomEvent to a live action.
(*Element) Slot(name string, c templ.Component)Fill a slot, wrapped in a <div>.
(*Element) SlotAs(tag, name string, c templ.Component)Fill a slot with a chosen wrapper.
(*Element) Children(templ.Component) / Text(string)Set children explicitly.
(*Element) Err() errorThe first problem recorded while building.
(*Element) Render(ctx, w) errorImplements templ.Component.
AttrName(prop string) stringProp name to attribute name, matching define.js exactly.
EncodeProp(v any) (string, bool, error)The prop encoding rules. ok is false when the attribute should be omitted.
EncodeAttr(v any) (string, bool, bool, error)The HTML attribute rules.
IsZero(v any) boolReflective zero check, used by generated wrappers for named types.
MaxSafeInteger1<<53 - 1. Beyond it, encoding is an error.
ErrUnsafeInteger, ErrNonFiniteFloatSentinels for the two numeric refusals.
ValidTagName(string) errorThe rule customElements.define enforces.
ValidAttrName(string) errorRejects names that would change a start tag’s structure.
RuntimeHandler() http.HandlerServes the vendored runtime, by file name, at any mount point.
Assets() fs.FSThe vendored files, for your own asset pipeline.
SetCacheHeaders(http.Header, *http.Request, etag string)The caching policy: immutable when the URL is versioned, revalidated otherwise.
RuntimeVersionThe alacris version vendored in this module.
UIVersionThe @alacris/ui version vendored in assets/ui/.
TrustedTypesPolicy"alacris". Allow it under a trusted-types CSP.
DefaultBase"/_alacris/".
AssetCore, AssetCoreDev, AssetStore, AssetContext, AssetSignal, AssetLive, AssetUI, AssetUIThemeServed file names.
ConfigBase, Dev, Modules, Imports, Live, Page, Endpoint, Nonce, Version, UI, Theme.
Scripts(Config) templ.ComponentThe import map, your modules, the UI bootstrap, and the live client. Goes in <head>.
(Config) ImportMap() map[string]stringThe specifiers it produces, for a bundler or a test.
PendingThe stylesheet that hides elements until they are defined.
Vars(names ...string) VarSetA contract from full property names. What generated code uses.
NewVarSet(prefix string, keys ...string) VarSetA contract from a prefix and camelCase keys, mirroring vars().
(VarSet) Name(key) string, Names() []string, Apply(*Element, map[string]string)The contract, and applying it.
Theme, ThemeColors, ThemeOverridesThe applyTheme config, set on Config.Theme.
import "github.com/bmartel/alacris-go/ui"

Typed wrappers for every Alacris UI component, generated from the vendored sources. Enable the JavaScript with alacris.Config{UI: true}. See Alacris UI.

Button, TextField, Dialog, …One constructor per tag.
Tags / Pending()For alacris.Pending.
ButtonVars, …Per-component theming contracts.
ButtonElement(sess, id)Typed live handles.
import "github.com/bmartel/alacris-go/gen"

For building the generator into your own tooling. The CLI is the usual way in.

Load(paths ...string) (*Manifest, error)Read components from JS files, directories, or manifests.
ParseFile, ParseDir, ParseSourceThe scanner directly.
Generate(*Manifest, Options) ([]File, error)Manifest to Go source.
WriteFiles(dir string, []File)Write, skipping files whose contents did not change.
Stale(dir string, []File) ([]string, error)Generated files this run did not produce.
ReadManifest, WriteManifestThe JSON form.
Manifest, Component, Prop, Event, Field, Slot, CSSProp, ImportThe manifest schema.
OptionsPackage, Import, Optional, StripPrefix, RelativeTo.
KindKindString, KindNumber, KindBool, KindJSON.
import "github.com/bmartel/alacris-go/live"
New(opts ...Options) *ServerA running server. Close it.
Mount(*http.ServeMux, base string, *Server)Runtime, client and endpoints in one call.
(*Server) NewSession(w, r) *SessionOne per page render. Reads or sets the cookie that authorises the browser, so it must run before anything is written.
(*Server) Session(id) (*Session, bool), Sessions() []*SessionLook them up.
(*Server) Broadcast(...Patch)Send to every session.
(*Server) On(action string, Handler)A server-wide handler.
(*Server) Close()End every session and stop the collector.
On[T](*Server, action, func(*Ctx, T) error)A handler with the detail decoded into T.
OnSession[T](*Session, action, func(*Ctx, T) error)The same, for one page.
(*Session) ID() stringThe page id to put in the page. Not a secret; the capability is the cookie.
(*Session) Context() context.ContextLives as long as the session. The context to render SetHTML with, not the request’s, which has finished by the time OnOpen runs.
(*Session) Element(id) HandleA handle for patching one element.
(*Session) Send(...Patch)Queue patches. Never blocks, never fails.
(*Session) Batch(func())Coalesce into one frame.
(*Session) OnOpen(func(*Session))Runs on every attach, including reconnects.
(*Session) Set(key, value any) / Get(key any)Per-page state.
(*Session) On(action string, Handler)A handler for this page, beating the server-wide one.
(*Session) Connected() bool, Closed() bool, Close()Lifecycle.
(Handle) Set(name string, v any)Write a component prop by its JavaScript name.
(Handle) SetAttr(name string, v any)An attribute; nil removes it.
(Handle) Class(name string, on bool)Toggle a class.
(Handle) Props(map[string]any)Several props, one frame.
(Handle) SetHTML(ctx, slot string, templ.Component) errorReplace one slot’s children.
Prop, Attr, Class, HTML, ReloadPatch constructors.
Patch, OpThe wire shape. See Wire protocol.
CtxSession, Action, Element, Detail, Request.
(*Ctx) Bind(v any) errorDecode the event detail, strictly.
(*Ctx) Handle() HandleThe element that emitted the event.
(*Ctx) Context() context.ContextThe request’s context.
OptionsTTL, Buffer, MaxDetail, MaxSessions, Heartbeat, AllowOrigin, Logger, Now, and the Cookie* fields.
SecureSecureAuto, SecureAlways, SecureNever: whether the cookie carries Secure.
DefaultCookieName"alacris_live".
ErrClosedReturned when a session has ended.
import "github.com/bmartel/alacris-go/app"

A nested module. Hosts the same http.Handler in an OS webview. Opening a window needs -tags desktop. See Desktop apps.

Run(Options) errorGated loopback, open a window, block until it closes.
New(Options) *App, (*App) Open(), (*App) Run(), (*App) NewWindow()The same, split, for a second window.
Listen(Options) (*Host, error)Loopback HTTP only. No display, no desktop tag, no host token.
(*Host) URL(), BootstrapURL(path), Shutdown(ctx)Bound origin, first-navigation URL, graceful stop.
WindowSetTitle, SetSize, SetPosition, Center, Minimize, Maximize, Fullscreen, Show, Hide, Focus, SetAlwaysOnTop, SetDecorations, SetBadge, Close, RegisterShortcut.
Menu, MenuItem, DefaultMenu, EditMenu, TrayNative menu bar and status item. Do is a Go callback.
OpenFile, SaveFile, SaveAs, Message, ConfirmOS dialogs. ErrCanceled on dismiss.
Notify, OpenURL, RevealInFileManager, WriteClipboard, ReadClipboardOS helpers. No desktop tag.
DataDir, CacheDirIdentifier-scoped directories.
Updater, ApplyAndRelaunch, Relaunch, FinishPendingUpdateed25519-signed updates and process replace.
ErrNoDesktop, ErrAlreadyRunning, ErrCanceled, ErrNoShortcut