wsutil

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 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

Overview

Package wsutil is a minimal RFC 6455 client, enough to drive the Discord gateway without pulling in a WebSocket dependency.

Scope: text and binary data frames with fragmentation, plus ping/pong/close control frames. Extensions (including permessage-deflate) are not negotiated.

Index

Constants

View Source
const (
	CloseNormal        = 1000
	CloseGoingAway     = 1001
	CloseProtocolErr   = 1002
	CloseMessageTooBig = 1009
)

Close codes used by this package.

Variables

View Source
var ErrClosed = errors.New("websocket: connection closed")

ErrClosed is returned once the connection has been closed.

Functions

This section is empty.

Types

type CloseError

type CloseError struct {
	Code   int
	Reason string
}

CloseError reports why the peer closed the connection.

func (*CloseError) Error

func (e *CloseError) Error() string

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn is a client-side WebSocket connection. It is safe for one concurrent reader and one concurrent writer.

func Dial

func Dial(rawURL string, opts *DialOptions) (*Conn, error)

Dial opens a WebSocket connection to a ws:// or wss:// URL.

func (*Conn) Close

func (c *Conn) Close(code int, reason string) error

Close sends a close frame and tears down the connection.

func (*Conn) Ping

func (c *Conn) Ping() error

Ping sends a ping frame.

func (*Conn) Read

func (c *Conn) Read() (opcode byte, data []byte, err error)

Read returns the next complete message, transparently answering pings and reassembling fragmented messages.

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

SetReadDeadline bounds how long the next Read may block.

func (*Conn) WriteBinary

func (c *Conn) WriteBinary(data []byte) error

WriteBinary sends a binary message.

func (*Conn) WriteText

func (c *Conn) WriteText(data []byte) error

WriteText sends a text message.

type DialOptions

type DialOptions struct {
	Header      http.Header
	Timeout     time.Duration
	MaxMessage  int64
	TLSConfig   *tls.Config
	Subprotocol string
}

DialOptions configures Dial.

Jump to

Keyboard shortcuts

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