Documentation
¶
Overview ¶
Package websocket-duplex demonstrates the DuplexPort — the sixth port type — served over a real WebSocket endpoint (adapters/websocket):
- ONE declaration: ports.NewDuplexPort + SocketPattern{Path: "/live/{room}"}
- clients send typed Command frames, the pipeline replies with typed Update frames — TARGETED to the sender's session, plus a broadcast
- one-struct convenience: SocketPattern InOpts/OutOpts auto-merge {room} into inbound/outbound payload structs
- escape hatch side-by-side: session routing still can use hub.SessionInfo directly (manual path), same payload, same adapter
- lifecycle wired through the app package (supervised Feed goroutine)
- observer pattern: app.Options.Observer pre-injects a stats.Observer into ctx; the adapter fires RecordRequest (upgrade), RecordSubscribe/ RecordPublish (frames), RecordValidationError (bad frame) — no adapter-specific observer interface needed
- logging: stats.NewFanout combines the metrics observer with a stats.LoggingObserver — every observer event is ALSO a structured slog line, from the same single injection point
A real gorilla client dials the loopback server, so the full upgrade → frame → codec → pipeline → targeted-reply path runs. Exits 0.
Running ¶
go run ./examples/websocket-duplex
Click to show internal directories.
Click to hide internal directories.