Documentation
¶
Overview ¶
Command widget is the widget SDK's smallest end-to-end host: two generated widgets, one registry, one page, one binary — and, behind one of them, a real consensus protocol.
Running it ¶
go run . # http://127.0.0.1:8080 go run . -addr 127.0.0.1:9000 go run . -nodes 5 # a five-node cluster; quorum becomes three go run . -heartbeat 400ms # a faster protocol, and a faster picture go run . -chaos 0 # elect once and never fail a node again
Nothing on the page was hand-written. examples/widget/clusterheartbeats and examples/widget/nodestatus are emitted from the two widget documents in pkg/widget/docs/examples by pkg/widget/gen.sh — the state, the reducers, the bindings, the labels, the SVG scenes and the motion — and this file registers them, hands the registry the four security decisions a library may not make for a host, and serves the result.
What to watch ¶
The raft card is drawing an election that is actually happening. Three goroutines in this process hold terms and cast votes at each other over channels — examples/widget/raftdemo, Raft's election half with no log — and one heartbeat round of that protocol is one snapshot is one round of pulses on the card. A pulse crossing an edge is a heartbeat that crossed a channel.
Every -chaos interval the current leader is crashed and, an interval later, restarted. The card's motion gate closes while the survivors campaign, its indicator turns, its scene's text alternative is rewritten, and the term in its stat line goes up by one when somebody wins — none of which is scripted, and all of which would look exactly the same if the failure were real. The button pauses the pulses, and a viewer who has asked for reduced motion never sees them at all. The node card's caption alternates between "reachable" and "unreachable" on a timer, because that widget has nothing behind it yet.
None of that behaviour is in this file. Events arrive, the generated reducers write state, and the generated bindings decide what everything says.
The two sources ¶
Each widget declared a stream it cannot open — a widget document names no host, no address and no credential, which is what makes one publishable — so resolving those names against something real is the host's job. Here "widget.cluster.watch" resolves to a subscription on the election running in this process and "widget.node-status.watch" resolves to a ticker.
The cluster is one per process and the subscription is one per session, which is the right way round: every browser watching is watching the same election rather than one private to it.
Security posture ¶
The three escape hatches are live.Anonymous, live.AllowAll[live.AnonymousIdentity] and live.NoCSRFCheck, each because a single-page demo has no accounts to check against. Origins is a real allowlist derived from the listen address rather than live.AnyOrigin, because that one has a production replacement worth showing.
templ: version: v0.3.1020
Directories
¶
| Path | Synopsis |
|---|---|
|
Command candaws is the CandaWS fleet: five parody cloud services, five engines, five generated widgets, and one binary.
|
Command candaws is the CandaWS fleet: five parody cloud services, five engines, five generated widgets, and one binary. |
|
blobfish
Package blobfish is the generated Blobfish widget.
|
Package blobfish is the generated Blobfish widget. |
|
coldstart
Package coldstart is the generated Coldstart widget.
|
Package coldstart is the generated Coldstart widget. |
|
dashbored
Package dashbored is the generated Dashbored widget.
|
Package dashbored is the generated Dashbored widget. |
|
fleet
Package fleet is the part of every CandaWS engine that is the same part.
|
Package fleet is the part of every CandaWS engine that is the same part. |
|
queuecumber
Package queuecumber is the generated Queuecumber widget.
|
Package queuecumber is the generated Queuecumber widget. |
|
yakshave
Package yakshave is the generated Yakshave widget.
|
Package yakshave is the generated Yakshave widget. |
|
Package clusterheartbeats is the generated ClusterHeartbeats widget.
|
Package clusterheartbeats is the generated ClusterHeartbeats widget. |
|
Package hosting is what both widget demo hosts do the same way.
|
Package hosting is what both widget demo hosts do the same way. |
|
Package nodestatus is the generated NodeStatus widget.
|
Package nodestatus is the generated NodeStatus widget. |
|
Package raftdemo runs a real leader election in one process, so that the raft widget beside it animates a protocol rather than a script.
|
Package raftdemo runs a real leader election in one process, so that the raft widget beside it animates a protocol rather than a script. |
|
Package relaypipeline is the generated RelayPipeline widget.
|
Package relaypipeline is the generated RelayPipeline widget. |