Monolith WebSocket Pub/Sub
Use this skill when
- •Building chat/live updates.
- •Debugging channel subscriptions or message broadcast behavior.
Entry points
- •Route:
GET /wsinapp/routes/routes.go - •Implementation:
ws/ws.go - •Persistent message model:
app/models/ws.go
Client protocol
Send JSON commands:
- •Subscribe:
{"command":"subscribe","identifier":"ChatChannel"} - •Publish:
{"command":"message","identifier":"ChatChannel","data":"Hello"}
Server behavior
- •Hub tracks channel subscriptions.
- •
messagecommands are persisted then broadcast to subscribed clients. - •Client loop handles register/unregister and ping/pong lifecycle.
Extension workflow
- •Pick channel naming strategy (room, user, domain event).
- •Add frontend websocket client logic in
static/js/application.jsor app-specific JS. - •Optionally enforce auth checks before allowing subscribe/publish.
- •Add tests in
ws/ws_test.gostyle for command handling.