Documentation
¶
Overview ¶
Package wsgateway serves the realtime WebSocket endpoint GET /api/v1/ws: authentication (the request's principal) plus the Origin check, the hello frame, resume and replay from the event log, live delivery from the hub, heartbeats, client signal frames and the close codes of docs/protocol.md.
Index ¶
Constants ¶
const ( DefaultPingInterval = 25 * time.Second DefaultDeadAfter = 60 * time.Second )
Heartbeat defaults (plan pipeline step 3).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway is the WebSocket handler. Mount it behind the auth middleware so the request carries its principal.
func (*Gateway) CloseAll ¶
CloseAll closes every open socket with code and reason (4010 server_reset, 4011 content_cleared, 1001 on shutdown) and waits, bounded, until their handlers have finished.
func (*Gateway) ServeHTTP ¶
func (g *Gateway) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP authenticates and upgrades the request, then serves the connection until it closes. Browser (cookie) principals must send an Origin that matches the request host, which blocks cross-site WebSocket hijacking; bearer clients are exempt.
type Options ¶
type Options struct {
// Hub delivers live events. Required.
Hub *events.Hub
// DB holds the instance row and the event log for resume. Required.
DB *store.DB
// Version is reported as server_version in hello.
Version string
// Logger receives connection failures; nil discards them.
Logger *slog.Logger
// PingInterval is the server ping period; 0 means DefaultPingInterval.
PingInterval time.Duration
// DeadAfter closes a connection that answered no ping for this long
// (and bounds a single write); 0 means DefaultDeadAfter.
DeadAfter time.Duration
}
Options configures New.