wsjson

package
v2.39.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.

func (*Decoder[T]) Close

func (d *Decoder[T]) Close() error

nolint: revive // complains that Encoder has the same function name

type Encoder

type Encoder[T any] struct {
	// contains filtered or unexported fields
}

func NewEncoder

func NewEncoder[T any](conn *websocket.Conn, typ websocket.MessageType) *Encoder[T]

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.

func (*Encoder[T]) Close

func (e *Encoder[T]) Close(c websocket.StatusCode) error

nolint: revive // complains that Decoder has the same function name

func (*Encoder[T]) Encode

func (e *Encoder[T]) Encode(v T) error

type Stream added in v2.22.0

type Stream[R any, W any] struct {
	// contains filtered or unexported fields
}

Stream is a two-way messaging interface over a WebSocket connection.

func NewStream added in v2.22.0

func NewStream[R any, W any](conn *websocket.Conn, readType, writeType websocket.MessageType, logger slog.Logger) *Stream[R, W]

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.

func (*Stream[R, W]) Close added in v2.22.0

func (s *Stream[R, W]) Close(c websocket.StatusCode) error

func (*Stream[R, W]) Drop added in v2.22.0

func (s *Stream[R, W]) Drop()

func (*Stream[R, W]) Send added in v2.22.0

func (s *Stream[R, W]) Send(v W) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL