Thanks to visit codestin.com
Credit goes to pkg.go.dev

wsjson

package
v2.21.3 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2025 License: AGPL-3.0 Imports: 6 Imported by: 0

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 starts the decoder reading from the websocket and returns a channel for reading the resulting values. The chan T is closed if the underlying websocket is closed, or we encounter an error. We also close the underlying websocket if we encounter an error reading or decoding.

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

Jump to

Keyboard shortcuts

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