websocket

package module
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: May 6, 2023 License: Apache-2.0 Imports: 8 Imported by: 7

README

Websocket

Test status Go Report Card GoDev GitHub release

Websocket implementation for Atreugo

Based on: fasthttp/websocket

Install

go get github.com/atreugo/websocket

How it works?

Go to examples to see how to use it.

Contributing

Feel free to contribute... 😉

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Specifies either the allowed origins.
	// The "*" wildcard, allow any origin.
	AllowedOrigins []string

	// HandshakeTimeout specifies the duration for the handshake to complete.
	HandshakeTimeout time.Duration

	// ReadBufferSize and WriteBufferSize specify I/O buffer sizes in bytes. If a buffer
	// size is zero, then buffers allocated by the HTTP server are used. The
	// I/O buffer sizes do not limit the size of the messages that can be sent
	// or received.
	ReadBufferSize, WriteBufferSize int

	// Subprotocols specifies the server's supported protocols in order of
	// preference. If this field is not nil, then the Upgrade method negotiates a
	// subprotocol by selecting the first match in this list with a protocol
	// requested by the client. If there's no match, then no protocol is
	// negotiated (the Sec-Websocket-Protocol header is not included in the
	// handshake response).
	Subprotocols []string

	// EnableCompression specify if the server should attempt to negotiate per
	// message compression (RFC 7692). Setting this value to true does not
	// guarantee that compression will be supported. Currently only "no context
	// takeover" modes are supported.
	EnableCompression bool

	// Error specifies the function for generating HTTP error responses. If Error
	// is nil, then http.Error is used to generate the HTTP response.
	Error atreugo.ErrorView

	// Logger is used for logging formatted messages.
	Logger *logger.Logger
}

Config configuration for upgrading an HTTP connection to a WebSocket connection.

type Conn

type Conn struct {
	*websocket.Conn
	// contains filtered or unexported fields
}

Conn represents a WebSocket connection.

func (*Conn) SetUserValue

func (ws *Conn) SetUserValue(key string, value interface{})

SetUserValue stores the given value (arbitrary object) under the given key.

The value stored may be obtained by UserValue*.

func (*Conn) SetUserValueBytes

func (ws *Conn) SetUserValueBytes(key []byte, value interface{})

SetUserValueBytes stores the given value (arbitrary object) under the given key.

The value stored may be obtained by UserValue*.

func (*Conn) UserValue

func (ws *Conn) UserValue(key string) interface{}

UserValue returns the value stored via SetUserValue* under the given key.

func (*Conn) UserValueBytes

func (ws *Conn) UserValueBytes(key []byte) interface{}

UserValueBytes returns the value stored via SetUserValue* under the given key.

type Upgrader

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

Upgrader tool to convert the websocket view to an atreugo view.

func New

func New(cfg Config) *Upgrader

New returns an upgrader tool.

func (*Upgrader) Upgrade

func (u *Upgrader) Upgrade(viewFn View) atreugo.View

Upgrade converts the websocket view to an atreugo view. The returned view upgrades the HTTP server connection to the WebSocket protocol.

All ctx.UserValues are stored in the websocket connection, being availables through ws.UserValue()

The responseHeader is included in the response to the client's upgrade request. Use the responseHeader to specify cookies (Set-Cookie) and the application negotiated subprotocol (Sec-WebSocket-Protocol).

If the upgrade fails, the view replies to the client with an HTTP error response.

type View

type View func(ws *Conn) error

View must process incoming websocket connections.

Jump to

Keyboard shortcuts

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