Documentation ¶
Overview ¶
Package websocket is a generated GoMock package.
Index ¶
- Constants
- Variables
- type Connection
- type ConnectionHub
- type Manager
- type MockUpgrader
- type MockUpgraderMockRecorder
- type Options
- func WithCheckOrigin(fn func(r *http.Request) bool) Options
- func WithCompression() Options
- func WithError(fn func(w http.ResponseWriter, r *http.Request, status int, reason error)) Options
- func WithHandshakeTimeout(t time.Duration) Options
- func WithReadBufferSize(size int) Options
- func WithSubprotocols(subprotocols ...string) Options
- func WithWriteBufferSize(size int) Options
- type Upgrader
- type WSKey
- type WSUpgrader
Constants ¶
const ( // TextMessage denotes a text data message. The text message payload is // interpreted as UTF-8 encoded text data. TextMessage = 1 )
The message types are defined in RFC 6455, section 11.8.
Variables ¶
var ErrorConnection = errors.New("couldn't establish connection to web socket")
ErrorConnection is the connection error that occurs when webscoket connection cannot be established.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
Connection is a wrapper for gorilla websocket connection.
func (*Connection) Bind ¶
func (w *Connection) Bind(v interface{}) error
func (*Connection) Context ¶
func (*Connection) Context() context.Context
func (*Connection) HostName ¶
func (*Connection) HostName() string
func (*Connection) Param ¶
func (*Connection) Param(_ string) string
func (*Connection) Params ¶ added in v1.16.0
func (*Connection) Params(string) []string
func (*Connection) PathParam ¶
func (*Connection) PathParam(_ string) string
type ConnectionHub ¶
type ConnectionHub struct { WebSocketConnections map[string]*Connection // contains filtered or unexported fields }
ConnectionHub stores and provide functionality to work with all active connections with websocket clients.
type Manager ¶
type Manager struct { ConnectionHub WebSocketUpgrader *WSUpgrader }
Manager is a websocket manager that handles the upgrader and manages all active connections thorugh ConnectionHub.
func New ¶
func New() *Manager
New intializes a new websocket manager with default websocket upgrader.
func (*Manager) AddWebsocketConnection ¶
func (ws *Manager) AddWebsocketConnection(connID string, conn *Connection)
AddWebsocketConnection add a new connection with the connection id key.
func (*Manager) CloseConnection ¶
CloseConnection closes a websocket connection and then removes it from the connection hub.
func (*Manager) GetWebsocketConnection ¶
func (ws *Manager) GetWebsocketConnection(connID string) *Connection
GetWebsocketConnection returns a websocket connection which has been intialized in the middleware.
type MockUpgrader ¶
type MockUpgrader struct {
// contains filtered or unexported fields
}
MockUpgrader is a mock of Upgrader interface.
func NewMockUpgrader ¶
func NewMockUpgrader(ctrl *gomock.Controller) *MockUpgrader
NewMockUpgrader creates a new mock instance.
func (*MockUpgrader) EXPECT ¶
func (m *MockUpgrader) EXPECT() *MockUpgraderMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
type MockUpgraderMockRecorder ¶
type MockUpgraderMockRecorder struct {
// contains filtered or unexported fields
}
MockUpgraderMockRecorder is the mock recorder for MockUpgrader.
type Options ¶
Options is a function type that applies a configuration to the concrete Upgrader.
func WithCheckOrigin ¶
WithCheckOrigin sets the CheckOrigin handler option.
func WithHandshakeTimeout ¶
WithHandshakeTimeout sets the HandshakeTimeout option.
func WithReadBufferSize ¶
WithReadBufferSize sets the ReadBufferSize option.
func WithSubprotocols ¶
WithSubprotocols sets the Subprotocols option.
func WithWriteBufferSize ¶
WithWriteBufferSize sets the WriteBufferSize option.
type Upgrader ¶
type Upgrader interface {
Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (*websocket.Conn, error)
}
Upgrader interface for upgrading HTTP connections to WebSocket connections.
type WSKey ¶
type WSKey string
WSKey defines the key type for WSConnectionKey.
const WSConnectionKey WSKey = "ws-connection-key"
WSConnectionKey is a key constant that stores the connection id in the request context.
type WSUpgrader ¶
type WSUpgrader struct {
Upgrader Upgrader
}
func NewWSUpgrader ¶
func NewWSUpgrader(opts ...Options) *WSUpgrader
NewWSUpgrader initialize a new websocket upgarder that upgrades an incoming http request to a websocket connection. It takes in Options that can be used to customize the upgraded connections.