websocket

package
v0.0.0-...-6527995 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWebsocketConnWrapper

func NewWebsocketConnWrapper(inner *websocket.Conn) *websocketConnWrapper

func Upgrade

func Upgrade(w http.ResponseWriter, r *http.Request) (*websocket.Conn, error)

Types

type Connection

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

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 ConnectionInterface interface {
	WriteText(body []byte) error
	WriteBinary(body []byte) error
	WriteJSON(body interface{}) error
	Close(status websocket.StatusCode, reason string)
}

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) Start

func (m *MockPool) Start()

func (*MockPool) UnregisterConnection

func (m *MockPool) UnregisterConnection(ConnectionInterface)

type MockWebsocketConn

type MockWebsocketConn struct {
	WriteJSONCalled bool
	WriteJSONErr    error
	CloseCalled     bool
}

func (*MockWebsocketConn) Close

func (m *MockWebsocketConn) Close(statusCode websocket.StatusCode, reason string) error

func (*MockWebsocketConn) Ping

func (m *MockWebsocketConn) Ping(ctx context.Context) error

func (*MockWebsocketConn) Read

func (*MockWebsocketConn) Subprotocol

func (m *MockWebsocketConn) Subprotocol() string

func (*MockWebsocketConn) Write

func (m *MockWebsocketConn) Write(ctx context.Context, messageType websocket.MessageType, p []byte) error

func (*MockWebsocketConn) WriteJSON

func (m *MockWebsocketConn) WriteJSON(ctx context.Context, v interface{}) error

type Pool

type Pool struct {
	Register      chan ConnectionInterface
	Unregister    chan ConnectionInterface
	Connections   map[ConnectionInterface]bool
	BroadcastJSON chan interface{}
}

func NewPool

func NewPool() *Pool

func (*Pool) BroadcastJSONMessage

func (pool *Pool) BroadcastJSONMessage(msg interface{})

func (*Pool) RegisterConnection

func (pool *Pool) RegisterConnection(conn ConnectionInterface)

func (*Pool) Start

func (pool *Pool) Start()

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
}

Jump to

Keyboard shortcuts

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