wsjson

package
v2.24.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 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 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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy