Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrConnectionClosed = errors.New("websocket connection closed")
ErrConnectionClosed is returned if trying to perform an operation on a closed connection
var ErrHandshake = errors.New("websocket handshake error")
ErrHandshake is returned if a request can not be upgraded to a websocket connection
Functions ¶
This section is empty.
Types ¶
type Message ¶
type Message struct { Type MessageType Data []byte }
Message has the actual data and the corresponding type that the data was sent as
type MessageType ¶
type MessageType int
MessageType represents a type of websocket message
const ( TextMessage MessageType = iota + 1 BinaryMessage )
MessageType constants
type Option ¶
type Option func(ws *websocket)
Option is used to alter the default behavior of the websocket connection. Options can be optionally passed to the Upgrade function.
func DisablePingPong ¶
func DisablePingPong() Option
DisablePingPong disables the pong/pong mecahnism and means that even if there is no communication the connection will be considered alive.
Default: false
func MaxMessageSize ¶
MaxMessageSize defines the maximum size allowed for messages that are read from clients. If a client attempts to send a larger message, an error will occur.
Default: 2048
func PongTimeout ¶
PongTimeout defines how long to wait for a pong response before determining the connection to be dead. Ping messages will be sent in intervals from which pong responses are expected.
Default: 60 seconds
func WriteTimeout ¶
WriteTimeout defines how long to wait for messages to be sent to the client before aborting. Setting it to zero means no timeout.
Default: 10 seconds
type Websocket ¶
type Websocket interface { // WriteText writes data as type Text over the websocket connection WriteText(data []byte) error // WriteBinary writes data as type Binary over the websocket connection WriteBinary(data []byte) error // Read subscribes to messages that are sent from the client. If there are // more than a single reader, the message will be passed to ONE of the reader // at random. Read() <-chan Message // Close will close the websocket connection Close() // OnClose can be used to get a signal when the connection is closed. If // the connection was closed due to a failure, the error that caused the // closing will be returned OnClose() chan error }
Websocket represents a websocket connection on which operations can be performed.