Documentation
¶
Index ¶
- type Client
- type Engine
- func (a *Engine) Auth() middleware.AuthFunc
- func (a *Engine) AuthMiddleware(next http.Handler) http.Handler
- func (a *Engine) BindClients(cs server.ClientSource)
- func (a *Engine) Cleanup()
- func (a *Engine) ClientModules() map[string]string
- func (a *Engine) Clients() []*Client
- func (a *Engine) ClientsWith(capability string) []*Client
- func (a *Engine) EmbeddedJS() (string, string, string)
- func (a *Engine) ExecJSDisabled() bool
- func (a *Engine) GetDisconnectBadgeHTML() string
- func (a *Engine) GetDisconnectHTML() string
- func (a *Engine) GetFaviconSVG() string
- func (a *Engine) GodomScriptPath() string
- func (a *Engine) Islands() []*island.Info
- func (a *Engine) ListenAndServe() error
- func (a *Engine) Mux() *http.ServeMux
- func (a *Engine) PluginScripts() map[string][]string
- func (a *Engine) QuickServe(isl interface{}) error
- func (a *Engine) Register(islands ...interface{})
- func (a *Engine) RegisterClientModule(name, js string)
- func (a *Engine) RegisterPartial(name, html string)
- func (a *Engine) RegisterPlugin(name string, scripts ...string)
- func (a *Engine) Run() error
- func (a *Engine) SetAuth(fn middleware.AuthFunc)
- func (a *Engine) SetFS(fsys fs.FS)
- func (a *Engine) SetMux(mux *http.ServeMux, opts *MuxOptions)
- func (a *Engine) Use(plugins ...PluginFunc)
- func (a *Engine) UsePartials(fsys fs.FS, baseDir string)
- func (a *Engine) WebSocketPath() string
- type Env
- type EnvAware
- type Island
- type MuxOptions
- type PluginFunc
- type Task
- type TaskOption
- type TaskPanic
- type Viewport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶ added in v0.2.0
Client is an addressable handle to one connected browser tab (one WebSocket). It is the foundation that per-connection features build on. A Client is per-socket: a reconnecting tab is a new Client with a new ID. Obtain Clients from Engine.Clients(); they are never constructed by application code.
type Engine ¶ added in v0.2.0
type Engine struct {
Port int // 0 = random available port
Host string // default "localhost"; set to "0.0.0.0" for network access
NoAuth bool // disable token auth (default false = auth enabled)
FixedAuthToken string // fixed auth token; empty = generate random token
NoBrowser bool // don't open browser on start
Quiet bool // suppress startup output
DisableExecJS bool // disable ExecJS — server won't send, bridge won't execute
DisconnectHTML string // custom disconnect overlay HTML (root mode); empty = default
DisconnectBadgeHTML string // custom disconnect badge HTML (embedded mode); empty = default
// contains filtered or unexported fields
}
Engine is the godom runtime. It registers islands and plugins, mounts the root island, and starts the server.
func (*Engine) Auth ¶ added in v0.2.0
func (a *Engine) Auth() middleware.AuthFunc
func (*Engine) AuthMiddleware ¶ added in v0.2.0
AuthMiddleware wraps an http.Handler with the configured auth function. If no auth is configured, returns the handler unwrapped. Must be called after Run().
func (*Engine) BindClients ¶ added in v0.2.0
func (a *Engine) BindClients(cs server.ClientSource)
BindClients is called by the server at startup to hand the engine the live connection roster. It is part of the internal EngineConfig wiring and is not intended for application use.
func (*Engine) Cleanup ¶ added in v0.2.0
func (a *Engine) Cleanup()
Cleanup closes event channels so island goroutines exit. Call this when your server is shutting down.
func (*Engine) ClientModules ¶ added in v0.2.0
ClientModules returns the registered client modules. Part of the internal EngineConfig wiring; not intended for application use.
func (*Engine) Clients ¶ added in v0.2.0
Clients returns a snapshot of the currently connected browser tabs. It returns nil before Run() has started the server. The returned slice is a fresh copy; the *Client values are stable per-connection handles safe to use as map keys.
func (*Engine) ClientsWith ¶ added in v0.2.0
ClientsWith returns the connected clients that have advertised the named module capability (via godom.declareCapability in the module's JS). Use it to fan a module call out only to the tabs that can actually handle it — keeping a replicated widget in sync without erroring on tabs that lack the module's prerequisites, or to find the single owner of a privileged capability.
func (*Engine) ExecJSDisabled ¶ added in v0.2.0
func (*Engine) GetDisconnectBadgeHTML ¶ added in v0.2.0
func (*Engine) GetDisconnectHTML ¶ added in v0.2.0
func (*Engine) GetFaviconSVG ¶ added in v0.2.0
func (*Engine) GodomScriptPath ¶ added in v0.2.0
func (*Engine) ListenAndServe ¶ added in v0.2.0
ListenAndServe binds a port using the startup config (Port, Host), wraps the mux with auth middleware if enabled, prints the URL, opens the browser, and serves. Must be called after Run().
func (*Engine) PluginScripts ¶ added in v0.2.0
func (*Engine) QuickServe ¶ added in v0.2.0
QuickServe is the convenience path for single-island apps. It registers the island as the root (document.body), creates a minimal page, sets up the mux, and serves. The island must have Template set before calling.
Example:
app := &App{Step: 1}
app.Template = "ui/index.html"
eng := godom.NewEngine()
eng.SetFS(ui)
log.Fatal(eng.QuickServe(app))
func (*Engine) Register ¶ added in v0.2.0
func (a *Engine) Register(islands ...interface{})
Register registers one or more islands. Each island must set TargetName and one of: TemplateHTML (inline), or Template+AssetsFS, or just Template with a shared SetFS() default on the engine.
func (*Engine) RegisterClientModule ¶ added in v0.2.0
RegisterClientModule ships a client-side JS module to every browser, exposed as window.godom.modules.<name>. The module script is responsible for assigning itself, e.g. `godom.modules.widget = { render: function(args){ ... } };`. Call a module function with typed args/reply via Client.Call / Client.CallAsync.
Targeting is explicit and the consumer's responsibility: use eng.Clients()-based fan-out to keep a replicated widget in sync across tabs, or call a single client for a singleton owner. Module state is not part of godom's VDOM sync.
func (*Engine) RegisterPartial ¶ added in v0.2.0
RegisterPartial registers a shared partial by name. When a template uses <my-button>, the engine resolves it by looking in (1) the island's local FS at the entry's baseDir, then (2) this registry. Use this for reusable HTML fragments shared across islands.
Example:
eng.RegisterPartial("brand-logo", `<img src="/logo.svg" alt="brand"/>`)
func (*Engine) RegisterPlugin ¶ added in v0.2.0
RegisterPlugin registers a named plugin with one or more JS scripts.
func (*Engine) Run ¶ added in v0.2.0
Run initializes the island lifecycle, registers /ws and /godom.js handlers on the mux set via SetMux, and starts event processors. If GODOM_VALIDATE_ONLY=1 is set, Run() returns immediately after validation succeeds — useful for CI and pre-commit checks.
func (*Engine) SetAuth ¶ added in v0.2.0
func (a *Engine) SetAuth(fn middleware.AuthFunc)
SetAuth sets a custom auth function. When set, godom uses it to protect /ws and (via AuthMiddleware/ListenAndServe) all routes. If not set and NoAuth is false, godom uses built-in token auth.
func (*Engine) SetFS ¶ added in v0.2.0
SetFS sets the default UI filesystem for island templates. It is used by Register() when an island does not carry its own AssetsFS. Optional — if every island brings its own AssetsFS or uses TemplateHTML, SetFS can be skipped.
func (*Engine) SetMux ¶ added in v0.2.0
func (a *Engine) SetMux(mux *http.ServeMux, opts *MuxOptions)
SetMux sets the HTTP mux. godom registers its handlers (/ws, /godom.js) on it. Must be called before Run().
func (*Engine) Use ¶ added in v0.2.0
func (a *Engine) Use(plugins ...PluginFunc)
Use registers one or more plugins with the engine.
func (*Engine) UsePartials ¶ added in v0.2.0
UsePartials bulk-registers partials from a filesystem. It scans baseDir inside fsys for *.html files and calls RegisterPartial(basename, content) for each. Sugar over RegisterPartial for the embed-a-directory case.
Example:
//go:embed partials var partials embed.FS eng.UsePartials(partials, "partials")
func (*Engine) WebSocketPath ¶ added in v0.2.0
type Env ¶ added in v0.2.0
Env is a connection's browser environment (timezone, locale, viewport) — the data Go cannot derive on its own. Read it via Client.Env().
type EnvAware ¶ added in v0.2.0
EnvAware is the optional interface an island implements to seed state from a new connection's environment. OnConnect(c *Client) runs once per connecting client, as an ordinary event on the island loop. Seeding a shared field from c.Env() is last-writer-wins across clients — correct for the single-environment case; for divergent per-client environments, scope by page or engine.
type Island ¶ added in v0.2.0
type Island struct {
TargetName string // matches g-island="name" attributes in parent templates
Template string // template path (resolved against AssetsFS or engine's SetFS)
TemplateHTML string // inline HTML; mutually exclusive with Template/AssetsFS
AssetsFS fs.FS // per-island filesystem for Template + sibling partials
// contains filtered or unexported fields
}
Island is embedded in user structs to make them godom islands. An island is a self-contained, stateful unit: its own goroutine, event queue, and VDOM tree. This is islands-architecture terminology — what other frameworks call "component" at the page level. See docs/why-islands.md.
Template sources, in order of precedence:
- TemplateHTML set: inline HTML is used directly (no filesystem involved).
- Template + AssetsFS set: read Template from AssetsFS.
- Template + engine's SetFS: read Template from the engine's shared FS.
func (*Island) Compute ¶ added in v0.2.0
Compute declares a computed field: Name is one of the island's own exported fields whose value the engine maintains by calling fn — a pure derivation of other fields — whenever any dep changes. The engine assigns fn's result to the field and surgically patches its bound nodes; fn itself must be cheap, pure, non-blocking, and must not mutate island state (do heavy or effectful work in a Task that writes a plain field the computed then reads).
Call Compute before Register (e.g. in a constructor or Init). Dependencies and the dependency graph are validated at Register: an unknown field, a duplicate computed, or a cycle aborts startup.
Example:
c.Compute("Subtotal", func() any { return c.Qty * c.UnitPrice }, "Qty", "UnitPrice")
c.Compute("SubtotalText", func() any { return money(c.Subtotal) }, "Subtotal")
func (*Island) ExecJS ¶ added in v0.2.0
ExecJS sends a JavaScript expression to all connected browsers for execution. The callback fires once per connected browser with the JSON-encoded result and an error string (empty on success).
Example:
c.ExecJS("location.pathname", func(result json.RawMessage, err string) {
var path string
json.Unmarshal(result, &path)
})
func (*Island) MarkRefresh ¶ added in v0.2.0
MarkRefresh marks fields for surgical refresh. The actual refresh happens when Refresh() is called (either by the user or automatically by the framework after a method call). Multiple calls accumulate.
func (*Island) Refresh ¶ added in v0.2.0
func (c *Island) Refresh()
Refresh pushes updates to all connected browsers. If fields were marked via MarkRefresh(), only those bound nodes are patched. Otherwise, a full refresh is sent.
Do not call Refresh inside methods invoked by browser events (e.g. g-click). The framework automatically refreshes after every method call, so calling Refresh there would result in a redundant double invocation. Use Refresh only from background goroutines (timers, tickers, async work).
func (*Island) Task ¶ added in v0.2.0
func (c *Island) Task(name string, fn func(*Task), opts ...TaskOption)
Task starts a named background task. The closure fn runs on a fresh goroutine off the island event loop, so it may block on I/O or compute. It must not write island fields directly — marshal every state change back with t.Apply, which runs on the loop and triggers a refresh. Pending/progress/error are bindable without app fields via Busy(name), Progress(name), Err(name), and Crashed(name).
Re-entry: by default a start is dropped while a task of the same name runs; use WithRestart() or WithQueue() to change that. Panics in the task body or its Apply closures are recovered and surfaced as Err(name)/Crashed(name) — they fail the task, not the process.
type MuxOptions ¶ added in v0.2.0
type MuxOptions struct {
WSPath string // WebSocket endpoint path (default "/ws")
ScriptPath string // godom.js script path (default "/godom.js")
}
MuxOptions configures custom paths for godom's handlers when using SetMux.
type PluginFunc ¶ added in v0.2.0
type PluginFunc func(*Engine)
PluginFunc sets up a plugin on an Engine.
type Task ¶ added in v0.2.0
Task is the handle passed to a task closure. The closure runs off the island event loop and must not touch island state directly; all state changes go through Task.Apply, which serializes them on the loop with renders. Cancellation is cooperative via Task.Cancelled / Task.Context.
type TaskOption ¶ added in v0.2.0
type TaskOption = island.TaskOption
TaskOption configures a Task start (WithRestart, WithQueue).
func WithQueue ¶ added in v0.2.0
func WithQueue() TaskOption
WithQueue runs the new task after the current one of the same name finishes, instead of the default (drop the new start while one is running).
func WithRestart ¶ added in v0.2.0
func WithRestart() TaskOption
WithRestart cancels an in-flight task of the same name and starts fresh. The superseded run's late results are fenced out and can never clobber the new run.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
async-tasks
command
Async tasks — managed background work, safe by construction.
|
Async tasks — managed background work, safe by construction. |
|
basic-form-builder
command
|
|
|
breakout-game
command
|
|
|
chart-plugins
command
|
|
|
charts-without-plugin
command
|
|
|
clock
command
|
|
|
computed-fields
command
Computed fields — derived values the engine keeps in sync for you.
|
Computed fields — derived values the engine keeps in sync for you. |
|
counter
command
|
|
|
crash-test
command
|
|
|
drag-demo
command
|
|
|
drag-tiles
command
|
|
|
dynamic-mount
command
|
|
|
embedded-widget
command
|
|
|
exec-and-call
command
|
|
|
multi-island
command
|
|
|
multi-page
command
|
|
|
multi-page-v2
command
multi-page-v2: demonstrates multiple tool islands (counter, clock, monitor, solar system) organized as separate Go packages, mounted on per-tool pages and a combined dashboard page.
|
multi-page-v2: demonstrates multiple tool islands (counter, clock, monitor, solar system) organized as separate Go packages, mounted on per-tool pages and a combined dashboard page. |
|
multi-page-v2/tools/digiclock
Package digiclock is a minimal digital clock island.
|
Package digiclock is a minimal digital clock island. |
|
multi-page-v2/tools/solar
Package solar is a 3D solar-system island: Go builds per-frame draw commands, a small canvas2D plugin on the bridge paints them.
|
Package solar is a 3D solar-system island: Go builds per-frame draw commands, a small canvas2D plugin on the bridge paints them. |
|
progress-bar
command
|
|
|
same-island-repeated
command
|
|
|
select-test
command
|
|
|
shared-state
command
|
|
|
solar-system
command
|
|
|
stock-ticker
command
|
|
|
sync-demo
command
|
|
|
todolist
command
|
|
|
video-player
command
|
|
|
ws-lifecycle
command
|
|
|
internal
|
|
|
vdom
Package vdom implements a virtual DOM tree with diffing and patching.
|
Package vdom implements a virtual DOM tree with diffing and patching. |
|
plugins
|
|
|
chartjs
Package chartjs provides a godom plugin for Chart.js integration.
|
Package chartjs provides a godom plugin for Chart.js integration. |
|
echarts
Package echarts provides a godom plugin for Apache ECharts integration.
|
Package echarts provides a godom plugin for Apache ECharts integration. |
|
plotly
Package plotly provides a godom plugin for Plotly.js integration.
|
Package plotly provides a godom plugin for Plotly.js integration. |



