Documentation ¶
Index ¶
- func ConvertErrorToStatusError(err error) error
- func MessageTypeFromProto(t roxy_v0.WebSocketFrame_Type) int
- func MessageTypeToProto(messageType int) roxy_v0.WebSocketFrame_Type
- type Adaptor
- type AdaptorOption
- type BinaryHandlerFunc
- type CloseError
- type CloseHandlerFunc
- type Looper
- type LooperOption
- func OnBinary(handler BinaryHandlerFunc) LooperOption
- func OnClose(handler CloseHandlerFunc) LooperOption
- func OnPing(handler PingHandlerFunc) LooperOption
- func OnPong(handler PongHandlerFunc) LooperOption
- func OnText(handler TextHandlerFunc) LooperOption
- func WithPingInterval(interval time.Duration) LooperOption
- func WithPongInterval(interval time.Duration) LooperOption
- type PingHandlerFunc
- type PongHandlerFunc
- type TextHandlerFunc
- type WebSocketConn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertErrorToStatusError ¶
ConvertErrorToStatusError converts an error (such as a CloseError) into a gRPC Status Error.
func MessageTypeFromProto ¶
func MessageTypeFromProto(t roxy_v0.WebSocketFrame_Type) int
MessageTypeFromProto converts a roxy_v0.WebSocketFrame_Type enum to a gorilla/websocket message type integer.
func MessageTypeToProto ¶
func MessageTypeToProto(messageType int) roxy_v0.WebSocketFrame_Type
MessageTypeToProto converts a gorilla/websocket message type integer to a roxy_v0.WebSocketFrame_Type enum.
Types ¶
type Adaptor ¶
type Adaptor struct {
// contains filtered or unexported fields
}
Adaptor wraps a websocket.Conn so that it can be used as a gRPC-like WebSocketConn suitable for use with Looper.
func MakeAdaptor ¶
func MakeAdaptor(conn *websocket.Conn, opts ...AdaptorOption) Adaptor
MakeAdaptor builds and returns an Adaptor.
type AdaptorOption ¶
type AdaptorOption func(*adaptorOptions)
AdaptorOption represents an option for building an Adaptor.
func WithReadLimit ¶
func WithReadLimit(limit int64) AdaptorOption
WithReadLimit specifies the maximum number of bytes to read per message for an Adaptor. See the websocket.Conn.SetReadLimit method for more information.
func WithReadTimeout ¶
func WithReadTimeout(timeout time.Duration) AdaptorOption
WithReadTimeout specifies the connection read timeout for an Adaptor. See the websocket.Conn.SetReadDeadline method for more information.
func WithWriteTimeout ¶
func WithWriteTimeout(timeout time.Duration) AdaptorOption
WithWriteTimeout specifies the connection write timeout for an Adaptor. See the websocket.Conn.SetWriteDeadline method for more information.
type BinaryHandlerFunc ¶
BinaryHandlerFunc is the type for an OnBinary handler.
type CloseError ¶
CloseError represents a WebSocket connection close event.
func CloseErrorFromBytes ¶
func CloseErrorFromBytes(p []byte) CloseError
CloseErrorFromBytes parses a CloseError from the payload bytes of a WebSocket CLOSE control message.
func (CloseError) AsBytes ¶
func (err CloseError) AsBytes() []byte
AsBytes renders this CloseError as bytes suitable for a CLOSE control message's payload.
func (CloseError) GRPCStatus ¶
func (err CloseError) GRPCStatus() *status.Status
GRPCStatus returns a gRPC Status which is roughly equivalent to this CloseError. The details of the original CloseError are stored in the Details field of the Status proto message, as type "roxy.v0.WebSocketCloseError".
func (CloseError) Is ¶
func (err CloseError) Is(other error) bool
Is returns true if this CloseError is equivalent to the given error.
Currently this method returns true in only two cases:
If this error has code 1000 (normal closure) and other is io.EOF.
If other is a gRPC Status Error with roxy_v0.WebSocketCloseError in its Details, and that roxy_v0.WebSocketCloseError has identical code and text to this error.
type CloseHandlerFunc ¶
type CloseHandlerFunc func(context.Context, *Looper, CloseError)
CloseHandlerFunc is the type for an OnClose handler.
type Looper ¶
type Looper struct {
// contains filtered or unexported fields
}
Looper is a construct for handling the mid-level details of operating a WebSocket-over-gRPC endpoint (client or server).
func NewLooper ¶
func NewLooper(ctx context.Context, conn WebSocketConn, opts ...LooperOption) *Looper
NewLooper constructs a new Looper for the given WebSocketConn.
func (*Looper) SendBinaryMessage ¶
SendBinaryMessage sends a BINARY data message.
It's safe to call this from any thread.
func (*Looper) SendClose ¶
SendClose sends a CLOSE control message.
It's safe to call this from any thread.
func (*Looper) SendPing ¶
SendPing sends a PING control message.
It's safe to call this from any thread.
You normally don't need to call this yourself.
func (*Looper) SendPong ¶
SendPong sends a PONG control message.
It's safe to call this from any thread.
You normally don't need to call this yourself.
func (*Looper) SendTextMessage ¶
SendTextMessage sends a TEXT data message.
It's safe to call this from any thread.
type LooperOption ¶
type LooperOption func(*looperOptions)
LooperOption represents an option for constructing a Looper.
func OnBinary ¶
func OnBinary(handler BinaryHandlerFunc) LooperOption
OnBinary specifies a handler for BINARY data messages.
func OnClose ¶
func OnClose(handler CloseHandlerFunc) LooperOption
OnClose specifies a handler for CLOSE control messages.
CLOSE messages will always be automatically reflected to the peer, regardless of whether or not an OnClose handler is specified and regardless of what actions the OnClose handler takes.
func OnPing ¶
func OnPing(handler PingHandlerFunc) LooperOption
OnPing specifies a handler for PING control messages.
PING messages will always be automatically reflected to the peer as PONG messages, regardless of whether or not an OnPing handler is specified and regardless of what actions the OnPing handler takes.
func OnPong ¶
func OnPong(handler PongHandlerFunc) LooperOption
OnPong specifies a handler for PONG control messages.
PONG messages will be automatically processed, regardless of whether or not an OnPong handler is specified and regardless of what actions the OnPong handler takes.
func OnText ¶
func OnText(handler TextHandlerFunc) LooperOption
OnText specifies a handler for TEXT data messages.
func WithPingInterval ¶
func WithPingInterval(interval time.Duration) LooperOption
WithPingInterval specifies the time interval between the receiving of a PONG control message and the sending of the next automatic PING control message.
func WithPongInterval ¶
func WithPongInterval(interval time.Duration) LooperOption
WithPongInterval specifies the time interval between the sending of an automatic PING control message and abandoning the connection because no PONG control message was received in response.
type PingHandlerFunc ¶
PingHandlerFunc is the type for an OnPing handler.
type PongHandlerFunc ¶
PongHandlerFunc is the type for an OnPong handler.
type TextHandlerFunc ¶
TextHandlerFunc is the type for an OnText handler.
type WebSocketConn ¶
type WebSocketConn interface { Send(*roxy_v0.WebSocketFrame) error Recv() (*roxy_v0.WebSocketFrame, error) }
WebSocketConn is the minimum subset of the roxy_v0.Web_SocketClient and roxy_v0.Web_SocketServer gRPC streams which is needed by Looper.
Implementations may optionally implement interface { CloseSend() error } as well, in which case CloseSend() will be called immediately after sending a CLOSE control message.