collab-server

command
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 13 Imported by: 0

README

collab-server example

A runnable example of embedding the ygo WebSocket sync server in your own Go backend and wiring its library-only extension points. It is documentation, not a product: cmd/yserve is the batteries-included CLI server driven by flags; this example shows what the server package exposes to code that mounts it, which the CLI cannot express.

Run

go run ./examples/collab-server              # in-memory
go run ./examples/collab-server -store x.db  # sqlite-backed (survives restart)

Then connect any y-websocket client:

ws://localhost:8080/collab/<docName>            # editor
ws://localhost:8080/collab/<docName>?mode=view  # read-only viewer

and check load:

curl http://localhost:8080/stats   # {"Documents":N,"Connections":M}

What it demonstrates

Everything is wired in newServer and documented in full on server.Options:

Piece Option What it shows
Persistence Store sqlite-backed history that survives restart (WAL, concurrency-safe)
Resource caps MaxConnsPerDoc, MaxDocs bound what one peer can pin in memory
Connection gate OnConnect / OnDisconnect request-aware accept/reject (headers, cookies, IP) and lifecycle logging
Read-only viewers ReadOnly ?mode=view receives updates and shows a cursor but cannot write
Change side effects OnChange react to every applied edit (index, webhook, mirror)
First-load seeding OnLoadDocument seed a fresh document's initial content with a stable-ID update
Live load Server.Stats() a /stats JSON endpoint, mounted beside the collab handler

The collab handler is mounted at /collab/ and the stats endpoint at /stats, so the stats path never collides with a document name.

The welcome seed is built once with a fixed ClientID so its item IDs are stable across reloads: OnLoadDocument re-applies it on every first load, and stable IDs make that idempotent without persisting the seed.

Documentation

Overview

Command collab-server is a runnable example of embedding the ygo WebSocket sync server in your own Go backend and wiring its library-only extension points: connection lifecycle hooks, read-only viewers, an on-change side effect, first-load seeding, resource caps, and a live stats endpoint. It is documentation, not a product — yserve (cmd/yserve) is the batteries-included CLI server; this shows what the server package exposes to code that embeds it.

Run:

go run ./examples/collab-server              # in-memory
go run ./examples/collab-server -store x.db  # sqlite-backed

Then point any y-websocket client at

ws://localhost:8080/collab/<docName>            # editor
ws://localhost:8080/collab/<docName>?mode=view  # read-only viewer

and GET http://localhost:8080/stats for current load.

Jump to

Keyboard shortcuts

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