examples/

directory
v1.61.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT

README

Examples

Runnable examples for embedding and using ygo. Each is a go run-able program with its own README and a test that runs it. collab-server and offline-first use SQLite and are modules of their own (cd into them to run them); the others build with the core module alone. collab-server and offline-first use the SQLite store, so each is a module of its own: run them from their directory (cd examples/collab-server && go run .). Run ./tools/go-work.sh once at the repository root first: they then build against this checkout (a release tag's checkout does not carry their checksums of that release, which are committed after its tags; without a workspace, go mod tidy in the example's directory fetches them). collab-client is part of the core module (go run ./examples/collab-client).

Example What it shows
collab-server Embed the WebSocket sync server and wire its hooks (OnConnect, ReadOnly, OnChange, OnLoadDocument), resource caps, a SQLite store, and a /stats endpoint
collab-client A Go-native sync client: connect, observe remote changes, edit, converge
offline-first Client-side offline persistence with a LocalStore: usable with no network, edits survive restarts and sync up on reconnect
collab-editor A collaborative text editor in the browser (yjs, y-websocket, y-codemirror.next from esm.sh, no build step) served by a ygo server
http-sync Sync over plain HTTP: two Go peers (client.HTTPSync) behind a bearer token, plus curl
peer-sync Documents that converge with no server: y-protocols messages (package protocol) over Go channels, live forwarding with OnUpdate, a late peer, an offline one
snapshot-history Snapshots: mark versions, store a few bytes each, read any version back (deleted text included)
cluster Two servers sharing documents and presence through a backplane, as instances behind a load balancer

The core CRDT API also has runnable, output-verified examples that render on pkg.go.dev (Map, Array, Text, two-document sync, UndoManager).

Directories

Path Synopsis
Command cluster runs two ygo servers that share their documents through a backplane, as instances behind a load balancer do.
Command cluster runs two ygo servers that share their documents through a backplane, as instances behind a load balancer do.
Command collab-client is a runnable example of the ygo Go-native sync client.
Command collab-client is a runnable example of the ygo Go-native sync client.
Command collab-editor serves a collaborative text editor: a ygo server and one web page that edits a shared document with the stock Yjs stack (yjs, y-websocket, y-codemirror.next, loaded from esm.sh: no npm, no build step).
Command collab-editor serves a collaborative text editor: a ygo server and one web page that edits a shared document with the stock Yjs stack (yjs, y-websocket, y-codemirror.next, loaded from esm.sh: no npm, no build step).
Command http-sync syncs documents over plain HTTP requests: no WebSocket, for scripts, cron jobs and serverless functions.
Command http-sync syncs documents over plain HTTP requests: no WebSocket, for scripts, cron jobs and serverless functions.
Command peer-sync shows how ygo documents converge with no server and no network: peers exchange y-protocols messages over Go channels.
Command peer-sync shows how ygo documents converge with no server and no network: peers exchange y-protocols messages over Go channels.
Command snapshot-history keeps a document's history readable: a snapshot marks a moment, and any marked version can be read back later, deleted text included.
Command snapshot-history keeps a document's history readable: a snapshot marks a moment, and any marked version can be read back later, deleted text included.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL