Documentation
¶
Index ¶
- Constants
- type ConnectionEvent
- type ConnectionType
- type EvtType
- type Logger
- type ResponseReader
- type SocketClientOpts
- type SocketConnection
- func (c *SocketConnection) Close() error
- func (c *SocketConnection) ID() string
- func (c *SocketConnection) ReadResponse() (*http.Response, error)
- func (c *SocketConnection) RoundTrip(req *http.Request) (*http.Response, error)
- func (c *SocketConnection) Serve(ctx context.Context, hdlr http.Handler)
- func (c *SocketConnection) WriteRequest(req *http.Request) error
- type SocketServerOpts
- type WebsocketClient
- type WebsocketServer
- func (ss *WebsocketServer) ActiveConnections() []*SocketConnection
- func (ss *WebsocketServer) ConnectionFromID(id string) *SocketConnection
- func (ss *WebsocketServer) ConnectionFromMetaData(meta interface{}) (string, error)
- func (ss *WebsocketServer) EventStream() (<-chan ConnectionEvent, error)
- func (ss *WebsocketServer) MetaData(cid string) interface{}
- func (ss *WebsocketServer) RemoteAddr(connID string) string
Constants ¶
const TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConnectionEvent ¶
type ConnectionType ¶
type ConnectionType int
ConnectionType is the socket connection type, it can either be a serverside connection or a clientside connection
const ( // ServerSide means this connection is owned by a websocket-server ServerSide ConnectionType = iota // ClientSide means this connection is owned by a websocket-client ClientSide )
type Logger ¶
type Logger interface { Print(...interface{}) Printf(string, ...interface{}) Println(...interface{}) }
Logger is the generic logger interface for in-app logging
type ResponseReader ¶
type ResponseReader struct {
// contains filtered or unexported fields
}
ResponseReader is a specialized reader that reads streams on websockets
type SocketClientOpts ¶
type SocketClientOpts struct { URL *url.URL KeepAlive bool PingHdlr func(string) error PongHdlr func(string) error AppData []byte Logger Logger }
SocketClientOpts is the options for a socket client
type SocketConnection ¶
type SocketConnection struct {
// contains filtered or unexported fields
}
SocketConnection is a wrapper around the websocket connection to handle http
func NewSocketConnection ¶
func NewSocketConnection(opts connectionOpts) *SocketConnection
NewSocketConnection creates a new socket connection
func (*SocketConnection) Close ¶
func (c *SocketConnection) Close() error
Close provides a graceful termination of the connection
func (*SocketConnection) ReadResponse ¶
func (c *SocketConnection) ReadResponse() (*http.Response, error)
ReadResponse reads a response from the underlying connection
func (*SocketConnection) RoundTrip ¶
RoundTrip implements the http RoundTripper interface. Must be safe for concurrent use by multiple goroutines
func (*SocketConnection) Serve ¶
func (c *SocketConnection) Serve(ctx context.Context, hdlr http.Handler)
func (*SocketConnection) WriteRequest ¶
func (c *SocketConnection) WriteRequest(req *http.Request) error
WriteRequest writes a request to the underlying connection
type SocketServerOpts ¶
type SocketServerOpts struct { Addr string KeepAlive bool PingHdlr func(string) error PongHdlr func(string) error AppData []byte Log Logger }
SocketServerOpts is the options for creating a websocket server
type WebsocketClient ¶
type WebsocketClient struct {
// contains filtered or unexported fields
}
WebsocketClient is the websockets client
func NewWebSocketClient ¶
func NewWebSocketClient(opts SocketClientOpts) *WebsocketClient
NewWebSocketClient creates a new websocketcient
func (*WebsocketClient) Connect ¶
func (sc *WebsocketClient) Connect() error
TODO refactor connect to return the connection instead of just an error. Creating a connection as a side effect is a bad idea Connect connects the websocket client to a server
func (*WebsocketClient) Connection ¶
func (sc *WebsocketClient) Connection() *SocketConnection
Connection returns the socketConnection object
func (*WebsocketClient) WithMetaData ¶
func (sc *WebsocketClient) WithMetaData(meta interface{}) *WebsocketClient
WithMetaData associates the socket client with app-level metadata
type WebsocketServer ¶
type WebsocketServer struct {
// contains filtered or unexported fields
}
func NewWebSocketServer ¶
func NewWebSocketServer(opts SocketServerOpts) *WebsocketServer
NewWebSocketServer creates a new websocket server
func (*WebsocketServer) ActiveConnections ¶
func (ss *WebsocketServer) ActiveConnections() []*SocketConnection
ActiveConnections returns all the active connections that the server currently has
func (*WebsocketServer) ConnectionFromID ¶
func (ss *WebsocketServer) ConnectionFromID(id string) *SocketConnection
ConnectionFromID returns the SocketConnection object from the connection-id
func (*WebsocketServer) ConnectionFromMetaData ¶
func (ss *WebsocketServer) ConnectionFromMetaData(meta interface{}) (string, error)
ConnectionFromMetaData returns the connection associated with the metadata
func (*WebsocketServer) EventStream ¶
func (ss *WebsocketServer) EventStream() (<-chan ConnectionEvent, error)
EventStream is the socket server's event stream
func (*WebsocketServer) MetaData ¶
func (ss *WebsocketServer) MetaData(cid string) interface{}
MetaData reads the metadata for some connection
func (*WebsocketServer) RemoteAddr ¶
func (ss *WebsocketServer) RemoteAddr(connID string) string
RemoteAddr returns the remote address