Documentation ¶
Index ¶
- Constants
- Variables
- func SandboxMessageHandler(ws *T, h Handler, msg *Message)
- func SandboxSubprotocol(f Subprotocol, ws *T)
- type AcceptOptionSetter
- type AcceptOptions
- type Cache
- type CompressionMode
- type Conn
- type Error
- type Fork
- type Framer
- type FramerMiddleware
- type Handler
- type HandlerFunc
- type JSON
- type Message
- type MessageSerializer
- type MessageType
- type Middleware
- type Observer
- type ObserverFunc
- type Path
- type Pather
- type Protocol
- type ProtocolFunc
- type RouteURI
- type Router
- type RouterFunc
- type StatusCode
- type Subprotocol
- type SubprotocolMap
- type T
- func (ws *T) Done() <-chan struct{}
- func (ws *T) ID() string
- func (ws *T) Reader() (MessageType, io.Reader, error)
- func (ws *T) Request() *http.Request
- func (ws *T) Subprotocol() string
- func (ws *T) Write(typ MessageType, buf []byte) error
- func (ws *T) WriteBinary(buf []byte) error
- func (ws *T) WriteMessage(msg *Message) error
- func (ws *T) WriteText(buf []byte) error
- func (ws *T) Writer(typ MessageType) (io.WriteCloser, error)
Constants ¶
const ( // MessageText = websocket.MessageText MessageText = websocket.MessageText // MessageBinary = websocket.MessageBinary MessageBinary = websocket.MessageBinary // CompressionNoContextTakeover = websocket.CompressionNoContextTakeover CompressionNoContextTakeover = websocket.CompressionNoContextTakeover // CompressionContextTakeover = websocket.CompressionContextTakeover CompressionContextTakeover = websocket.CompressionContextTakeover // CompressionDisabled = websocket.CompressionDisabled CompressionDisabled = websocket.CompressionDisabled // StatusNormalClosure StatusCode = 1000 StatusNormalClosure = websocket.StatusNormalClosure // StatusGoingAway StatusCode = 1001 StatusGoingAway = websocket.StatusGoingAway // StatusProtocolError StatusCode = 1002 StatusProtocolError = websocket.StatusProtocolError // StatusUnsupportedData StatusCode = 1003 StatusUnsupportedData = websocket.StatusUnsupportedData // StatusNoStatusRcvd StatusCode = 1005 StatusNoStatusRcvd = websocket.StatusNoStatusRcvd // StatusAbnormalClosure StatusCode = 1006 StatusAbnormalClosure = websocket.StatusAbnormalClosure // StatusInvalidFramePayloadData StatusCode = 1007 StatusInvalidFramePayloadData = websocket.StatusInvalidFramePayloadData // StatusPolicyViolation StatusCode = 1008 StatusPolicyViolation = websocket.StatusPolicyViolation // StatusMessageTooBig StatusCode = 1009 StatusMessageTooBig = websocket.StatusMessageTooBig // StatusMandatoryExtension StatusCode = 1010 StatusMandatoryExtension = websocket.StatusMandatoryExtension // StatusInternalError StatusCode = 1011 StatusInternalError = websocket.StatusInternalError // StatusServiceRestart StatusCode = 1012 StatusServiceRestart = websocket.StatusServiceRestart // StatusTryAgainLater StatusCode = 1013 StatusTryAgainLater = websocket.StatusTryAgainLater // StatusBadGateway StatusCode = 1014 StatusBadGateway = websocket.StatusBadGateway // StatusTLSHandshake StatusCode = 1015 StatusTLSHandshake = websocket.StatusTLSHandshake )
Variables ¶
var ( // ErrTooFast indicates the connection is sending too fast ErrTooFast = StatusError(StatusPolicyViolation, "websocket: too fast") // ErrDataType indicates the connection sent badly typed data ErrDataType = StatusError(StatusInvalidFramePayloadData, "websocket: data type") )
Functions ¶
func SandboxMessageHandler ¶
SandboxSubprotocol runs a MessageHandler to completion
func SandboxSubprotocol ¶
func SandboxSubprotocol(f Subprotocol, ws *T)
SandboxSubprotocol runs a subprotocol to completion
Types ¶
type AcceptOptionSetter ¶
type AcceptOptionSetter interface {
SetAcceptOption(a *AcceptOptions)
}
func WithCompressionMode ¶
func WithCompressionMode(c CompressionMode) AcceptOptionSetter
func WithCompressionThreshold ¶
func WithCompressionThreshold(c int) AcceptOptionSetter
func WithInsecureSkipVerify ¶
func WithInsecureSkipVerify(b bool) AcceptOptionSetter
func WithOriginPatterns ¶
func WithOriginPatterns(s []string) AcceptOptionSetter
type AcceptOptions ¶
type AcceptOptions = websocket.AcceptOptions
AcceptOptions = websocket.AcceptOptions
type Cache ¶
type Cache struct { maps.Observable[string, *T] // contains filtered or unexported fields }
type CompressionMode ¶
type CompressionMode = websocket.CompressionMode
CompressionMode = websocket.CompressionMode
type Error ¶
type Error interface { error StatusCode() StatusCode }
func StatusError ¶
func StatusError(code StatusCode, err string) Error
type Fork ¶
type Fork []Pather
Fork is a Pather made of []Pather
type Framer ¶
type Framer = func(*T, MessageType, io.Reader) error
Framer is a func type for websocket connection handler
func MessageFramer ¶
func MessageFramer(s MessageSerializer, handler Handler) Framer
MessageFramer creates a Framer from a MessageHandler
type FramerMiddleware ¶
type Handler ¶
Handler is analogous to http.Handler
func Use ¶
func Use(h Handler, m ...Middleware) Handler
func Using ¶
func Using(ms []Middleware, h Handler) Handler
type HandlerFunc ¶
HandlerFunc is a func type for Handler
func (HandlerFunc) ServeWS ¶
func (f HandlerFunc) ServeWS(ws *T, msg *Message)
type Message ¶
Message is a simple data messaging type for MessageType=MessageText
func NewMessage ¶
NewMessage creates a structured JSON message with the given type
type MessageSerializer ¶
type MessageSerializer interface { Encode(Message) ([]byte, error) Decode([]byte) (*Message, error) }
MessageSerializer marshals and unmarshals Messages
type Middleware ¶
Middleware is a consumer type that manipulates Handlers
type ObserverFunc ¶
type ObserverFunc = maps.ObserverFunc[string, *T]
type Protocol ¶
type Protocol interface { // GetSubprotocols returns the list of supported Subprotocol names GetSubprotocols() []string // GetSubprotocol returns the Subprotocol GetSubprotocol(string) Subprotocol }
Protocol is an interface for acquiring Subprotocol
func MessageProtocol ¶
func MessageProtocol(enc MessageSerializer, handler Handler) Protocol
MessageProtocol returns Protocol from ProtocolFunc and MessageSubprotocol
func MessageProtocolName ¶
func MessageProtocolName(subprotoName string, enc MessageSerializer, handler Handler) Protocol
MessageProtocolName returns Protocol from SubprotocolMap and MessageSubprotocol
type ProtocolFunc ¶
type ProtocolFunc Subprotocol
ProtocolFunc is a quick-n-dirty Protocol that is only 1 Subprotocol
func (ProtocolFunc) GetSubprotocol ¶
func (f ProtocolFunc) GetSubprotocol(name string) Subprotocol
GetSubprotocol implements Protocol by returning f when name==""
func (ProtocolFunc) GetSubprotocols ¶
func (ProtocolFunc) GetSubprotocols() []string
GetSubprotocols implements Protocol
type RouterFunc ¶
RouterFunc creates a match using a func pointer
func (RouterFunc) RouteWS ¶
func (f RouterFunc) RouteWS(msg *Message) bool
type Subprotocol ¶
Subprotocol is a connection handler
func MessageSubprotocol ¶
func MessageSubprotocol(enc MessageSerializer, handler Handler) Subprotocol
MessageSubprotocol returns Subprotocol from NewSubprotocol and MessageFramer
func NewSubprotocol ¶
func NewSubprotocol(f Framer) Subprotocol
NewSubprotocol creates a frame-based read-limited Subprotocol
type SubprotocolMap ¶
type SubprotocolMap map[string]Subprotocol
SubprotocolMap is builtin map Protocol
func (SubprotocolMap) GetSubprotocol ¶
func (m SubprotocolMap) GetSubprotocol(name string) Subprotocol
GetSubprotocol implements Protocol
func (SubprotocolMap) GetSubprotocols ¶
func (m SubprotocolMap) GetSubprotocols() []string
GetSubprotocols implements Protocol
type T ¶
type T struct {
// contains filtered or unexported fields
}
T is a Websocket
func (*T) Reader ¶
func (ws *T) Reader() (MessageType, io.Reader, error)
Reader exposes the websocket Reader API and must only be called synchronously
func (*T) Subprotocol ¶
Subprotocol returns the name of the negotiated subprotocol
func (*T) WriteBinary ¶
func (*T) WriteMessage ¶
func (*T) Writer ¶
func (ws *T) Writer(typ MessageType) (io.WriteCloser, error)
Writer exposes the websocket API and may be called asynchronously