Movatterモバイル変換


[0]ホーム

URL:


wsjson

package
v2.23.0Latest Latest
Warning

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

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

Details

Repository

github.com/coder/coder

Links

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

typeDecoder

type Decoder[Tany] struct {// contains filtered or unexported fields}

funcNewDecoder

func NewDecoder[Tany](conn *websocket.Conn, typwebsocket.MessageType, loggerslog.Logger) *Decoder[T]

NewDecoder creates a JSON-over-websocket decoder for type T, which must be deserializable fromJSON.

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 anerror reading from the WebSocket or decoding a value the WebSocket will beclosed.

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

typeEncoder

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

funcNewEncoder

func NewEncoder[Tany](conn *websocket.Conn, typwebsocket.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 thewebsocket for reading, turning it into a unidirectional write stream of JSON-encoded objects.

func (*Encoder[T])Close

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

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

func (*Encoder[T])Encode

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

typeStreamadded inv2.22.0

type Stream[Rany, Wany] struct {// contains filtered or unexported fields}

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

funcNewStreamadded inv2.22.0

func NewStream[Rany, Wany](conn *websocket.Conn, readType, writeTypewebsocket.MessageType, loggerslog.Logger) *Stream[R, W]

func (*Stream[R, W])Chanadded inv2.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 anerror reading from the WebSocket or decoding a value the WebSocket will beclosed.

Safety: Chan must only be called once. Successive calls will panic.

func (*Stream[R, W])Closeadded inv2.22.0

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

func (*Stream[R, W])Dropadded inv2.22.0

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

func (*Stream[R, W])Sendadded inv2.22.0

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

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp