websocket-duplex

command
v0.12.0 Latest Latest
Warning

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

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

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

Jump to

Keyboard shortcuts

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