Documentation
¶
Overview ¶
websocket demonstrates a browser-friendly WebSocket route:
- GET / serves a tiny HTML client.
- WebSocket /ws uses middleware.WebSocketAuth for origin, token, and subprotocol checks.
- Upgrade verification returns per-connection state as UserData.
- Open subscribes each connection to a room.
- Message publishes text frames to the other subscribers.
Run:
CGO_ENABLED=1 go run -tags gogo ./examples/websocket
Then open http://localhost:3004/ in a browser.
Or connect from the CLI:
websocat -H='Origin: http://localhost:3004' -H='Sec-WebSocket-Protocol: chat.v1' 'ws://localhost:3004/ws?name=cli&room=general&token=demo-local-token'
Click to show internal directories.
Click to hide internal directories.