Documentation ¶
Index ¶
- func NewWebsocketConnWrapper(inner *websocket.Conn) *websocketConnWrapper
- func Upgrade(w http.ResponseWriter, r *http.Request) (*websocket.Conn, error)
- type Connection
- type ConnectionInterface
- type Message
- type MockConnection
- type MockPool
- type MockWebsocketConn
- func (m *MockWebsocketConn) Close(statusCode websocket.StatusCode, reason string) error
- func (m *MockWebsocketConn) Ping(ctx context.Context) error
- func (m *MockWebsocketConn) Read(ctx context.Context) (websocket.MessageType, []byte, error)
- func (m *MockWebsocketConn) Subprotocol() string
- func (m *MockWebsocketConn) Write(ctx context.Context, messageType websocket.MessageType, p []byte) error
- func (m *MockWebsocketConn) WriteJSON(ctx context.Context, v interface{}) error
- type Pool
- type PoolInterface
- type WebsocketConnWrapperInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewWebsocketConnWrapper ¶
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
func NewConnection ¶
func NewConnection(conn WebsocketConnWrapperInterface, pool PoolInterface) *Connection
func (*Connection) Close ¶
func (c *Connection) Close(status websocket.StatusCode, reason string)
func (*Connection) WriteBinary ¶
func (c *Connection) WriteBinary(body []byte) error
func (*Connection) WriteJSON ¶
func (c *Connection) WriteJSON(body interface{}) error
func (*Connection) WriteText ¶
func (c *Connection) WriteText(body []byte) error
type ConnectionInterface ¶
type Message ¶
type Message struct { Type websocket.MessageType `json:"type"` Body string `json:"body"` }
type MockConnection ¶
type MockConnection struct { WriteJSONCalled bool ReceivedMessage interface{} // contains filtered or unexported fields }
func (*MockConnection) Close ¶
func (m *MockConnection) Close(status websocket.StatusCode, reason string)
func (*MockConnection) WriteBinary ¶
func (m *MockConnection) WriteBinary(body []byte) error
func (*MockConnection) WriteJSON ¶
func (m *MockConnection) WriteJSON(body interface{}) error
func (*MockConnection) WriteText ¶
func (m *MockConnection) WriteText(body []byte) error
type MockPool ¶
type MockPool struct { RegisterCalled bool UnregisterCalled bool BroadcastJSONCalled bool BroadcastMsg interface{} }
func (*MockPool) BroadcastJSONMessage ¶
func (m *MockPool) BroadcastJSONMessage(msg interface{})
func (*MockPool) RegisterConnection ¶
func (m *MockPool) RegisterConnection(ConnectionInterface)
func (*MockPool) UnregisterConnection ¶
func (m *MockPool) UnregisterConnection(ConnectionInterface)
type MockWebsocketConn ¶
func (*MockWebsocketConn) Close ¶
func (m *MockWebsocketConn) Close(statusCode websocket.StatusCode, reason string) error
func (*MockWebsocketConn) Read ¶
func (m *MockWebsocketConn) Read(ctx context.Context) (websocket.MessageType, []byte, error)
func (*MockWebsocketConn) Subprotocol ¶
func (m *MockWebsocketConn) Subprotocol() string
func (*MockWebsocketConn) Write ¶
func (m *MockWebsocketConn) Write(ctx context.Context, messageType websocket.MessageType, p []byte) error
type Pool ¶
type Pool struct { Register chan ConnectionInterface Unregister chan ConnectionInterface Connections map[ConnectionInterface]bool BroadcastJSON chan interface{} }
func (*Pool) BroadcastJSONMessage ¶
func (pool *Pool) BroadcastJSONMessage(msg interface{})
func (*Pool) RegisterConnection ¶
func (pool *Pool) RegisterConnection(conn ConnectionInterface)
func (*Pool) UnregisterConnection ¶
func (pool *Pool) UnregisterConnection(conn ConnectionInterface)
type PoolInterface ¶
type PoolInterface interface { Start() RegisterConnection(ConnectionInterface) UnregisterConnection(ConnectionInterface) BroadcastJSONMessage(interface{}) }
type WebsocketConnWrapperInterface ¶
type WebsocketConnWrapperInterface interface { Subprotocol() string Ping(ctx context.Context) error Read(ctx context.Context) (websocket.MessageType, []byte, error) Write(ctx context.Context, messageType websocket.MessageType, payload []byte) error Close(status websocket.StatusCode, reason string) error WriteJSON(ctx context.Context, body interface{}) error }
Click to show internal directories.
Click to hide internal directories.