websocket

package
v0.0.0-...-1c4d217 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleWebSocket

func HandleWebSocket(handler func(*Conn), config ...Config) fiber.Handler

HandleWebSocket returns a new `handler func(*Conn)` that upgrades a client to the websocket protocol, you can pass an optional config.

Types

type Config

type Config struct {

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

	// Subprotocols specifies the client's requested subprotocols.
	Subprotocols []string

	// Allowed Origin's based on the Origin header, this validate the request origin to
	// prevent cross-site request forgery. Everything is allowed if left empty.
	Origins []string

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

	// EnableCompression specifies if the client 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
}

Config ...

type Conn

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

Conn represents connection with its parameters, cookies, query string etc

func (*Conn) Cookies

func (conn *Conn) Cookies(key string, defaultValue ...string) string

Cookies is used for getting a cookie value by key Defaults to empty string "" if the cookie doesn't exist. If a default value is given, it will return that value if the cookie doesn't exist.

func (*Conn) Locals

func (conn *Conn) Locals(key string) interface{}

Locals makes it possible to pass interface{} values under string keys scoped to the request and therefore available to all following routes that match the request.

func (*Conn) Params

func (conn *Conn) Params(key string, defaultValue ...string) string

Params is used to get the route parameters. Defaults to empty string "" if the param doesn't exist. If a default value is given, it will return that value if the param doesn't exist.

func (*Conn) Query

func (conn *Conn) Query(key string, defaultValue ...string) string

Query returns the query string parameter in the url. Defaults to empty string "" if the query doesn't exist. If a default value is given, it will return that value if the query doesn't exist.

Jump to

Keyboard shortcuts

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