Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder[T any] struct { // contains filtered or unexported fields }
func NewDecoder ¶
func NewDecoder[T any](conn *websocket.Conn, typ websocket.MessageType, logger slog.Logger) *Decoder[T]
NewDecoder creates a JSON-over-websocket decoder for type T, which must be deserializable from JSON.
func (*Decoder[T]) Chan ¶
func (d *Decoder[T]) Chan() <-chan T
Chan returns a `chan` that you can read incoming messages from. The returned `chan` will be closed when the WebSocket connection is closed. If there is an error reading from the WebSocket or decoding a value the WebSocket will be closed.
Safety: Chan must only be called once. Successive calls will panic.
type Encoder ¶
type Encoder[T any] struct { // contains filtered or unexported fields }
func NewEncoder ¶
NewEncoder creates a JSON-over websocket encoder for the type T, which must be JSON-serializable. You may then call Encode() to send objects over the websocket. Creating an Encoder closes the websocket for reading, turning it into a unidirectional write stream of JSON-encoded objects.
type Stream ¶ added in v2.22.0
Stream is a two-way messaging interface over a WebSocket connection.
func (*Stream[R, W]) Chan ¶ added in v2.22.0
func (s *Stream[R, W]) Chan() <-chan R
Chan returns a `chan` that you can read incoming messages from. The returned `chan` will be closed when the WebSocket connection is closed. If there is an error reading from the WebSocket or decoding a value the WebSocket will be closed.
Safety: Chan must only be called once. Successive calls will panic.