Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn interface {
ReadMessage() (messageType int, p []byte, err error)
WriteMessage(messageType int, data []byte) error
WriteControl(messageType int, data []byte, deadline time.Time) error
SetCloseHandler(h func(code int, text string) error)
Close() error
}
Conn interfaces out the underlying (gorilla) websocket implementation, so we can mock it out easily when testing, etc.
func NewWebsocketConn ¶
NewWebsocketConn creates a websocket Conn
type Dialer ¶
type Dialer interface {
// Dial opens a websocket connection from the client
Dial(urlStr string, requestHeader http.Header) (Conn, *http.Response, error)
}
Dialer interface
type Hub ¶
type Hub interface {
// Dial handshakes websocket connection from client side
Dial(urlStr string, requestHeader http.Header) (Conn, *http.Response, error)
// Upgrade handshakes and upgrades websocket connection from server side
Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (Conn, error)
}
Hub is the interface for websocket Hub that can be used to establish websocket connection
type Stream ¶
type Stream interface {
// Start starts the stream
Start() error
// Write writes a message into the buffer
Write(thrift.TStruct) error
// Flush flushes out buffered messages
Flush() error
// Read reads and returns a message
Read() (thrift.TStruct, error)
// CloseWrite closes the write-path
CloseWrite() error
// Close shuts down read/write path and closes the underlying connection
Close() error
}
Stream defines the interface for the "stream", that implements the shared functionality between the server and the client ends of the stream
func NewStream ¶
func NewStream(conn Conn, opts *StreamOpts) Stream
NewStream initializes a new stream object
type StreamClient ¶
type StreamClient interface {
// Start starts the stream-client
Start() error
// Write writes a message into the write buffer
Write(thrift.TStruct) error
// Flush flushes out buffered messages
Flush() error
// Read reads and returns a message
Read() (thrift.TStruct, error)
// Done is used to indicate that the client is done
Done() error
}
StreamClient defines the interface for the 'client' side of the stream
func NewStreamClient ¶
func NewStreamClient(url string, requestHeader http.Header, dialer Dialer, readMsgType reflect.Type) StreamClient
NewStreamClient initializes a websocket-streaming client to the given url
type StreamOpts ¶
type StreamOpts struct {
// Server indicates whether the stream should be configured to behave
// like the "server" end of the connection.
Server bool
// FlushThreshold is the number of messages to buffer before flushing automatically
FlushThreshold int
// PingInterval is the interval at which websocket ping-messages need to be sent; if
// this is zero, pings will not be sent
PingInterval time.Duration
// readMsgType is the type of read-message
ReadMsgType reflect.Type
}
StreamOpts are the options passed when creating the stream
type StreamServer ¶
type StreamServer interface {
// Start starts the stream-server
Start() error
// Write writes a message into the write buffer
Write(msg thrift.TStruct) (err error)
// Flush flushes out buffered messages
Flush() (err error)
// Read reads and returns a message
Read() (msg thrift.TStruct, err error)
// Done is used to indicate that the server is done
Done() (err error)
}
StreamServer defines the interface for the 'server' side of the stream that batches responses/requests
func NewStreamServer ¶
func NewStreamServer(httpRespWriter http.ResponseWriter, httpRequest *http.Request, upgrader Upgrader, readMsgType reflect.Type) StreamServer
NewStreamServer initializes a new websocket-streaming server