Documentation
¶
Overview ¶
Package ws provides essessey.Sink and essessey.Source bindings for WebSocket connections.
WebSocket is message-oriented: every write is already a discrete frame, so this package needs no SSE-style framing — that framing exists only because an HTTP body is an undelimited byte stream. Sink sends the whole essessey.Event as one JSON message; Source hands events back exactly as they were delivered.
This package deliberately does NOT import a websocket library such as github.com/gorilla/websocket. Conn declares the one method (WriteJSON(v any) error) this package actually needs, and gorilla's *websocket.Conn already satisfies it structurally — the caller passes their own connection, and essessey adds zero transport dependency. This is a design choice, not a missing feature: pulling in a websocket library would tie essessey's module graph to one driver version for the sake of a single method.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
Conn is the minimal capability this package needs from a WebSocket connection: write a value as one JSON-encoded frame.
gorilla's *websocket.Conn (github.com/gorilla/websocket) satisfies this method as-is. Callers pass their own connection — see the package doc comment for why this package never imports a websocket library itself.
type Sink ¶
type Sink struct {
// contains filtered or unexported fields
}
Sink writes essessey events to a WebSocket connection.
WebSocket already delimits frames, so Emit sends the whole essessey.Event as one WriteJSON call — no SSE-style framing. The client receives {"event": ..., "data": ...} on the wire.
Unlike a NATS connection, gorilla's *websocket.Conn permits only one writer at a time, so Emit is mutex-guarded to stay safe for concurrent use.
type Source ¶
type Source struct {
// contains filtered or unexported fields
}
Source turns a WebSocket read loop's per-message delivery into an essessey.Source. Wire Deliver as the callback the read loop invokes per inbound message; Next pulls events off in the order they arrived.
func (*Source) Close ¶
func (s *Source) Close()
Close stops the source. Next drains any already-buffered events first, then returns essessey.ErrNoMoreEvents. Close is idempotent.