Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { AddMiddleware(middleware Middleware) NewConnection(conn *websocket.Conn) Connection }
type Connection ¶
type Connection interface { ResponseWriter // Close closes the connection. // If the connection is already closed, an error is returned. Close() error // Wait returns a channel that is closed when the connection is closed. Wait() <-chan struct{} }
type JSONResolver ¶
type JSONResolver struct {
// contains filtered or unexported fields
}
func NewJSONResolver ¶
func NewJSONResolver(field string) *JSONResolver
NewJSONResolver creates a new JSONResolver instance. field is the name of the field in the JSON message that is used to resolve the handler. For example, if field is "type", the message {"type": "sum-request", "a": 1, "b": 2} is resolved to the handler registered for "sum-request". If the field is nested, use dot notation, e.g. "type.name".
func (*JSONResolver) AddHandler ¶
func (r *JSONResolver) AddHandler(name string, handler Handler) *JSONResolver
AddHandler adds a handler for a message type. name is the value of the field that is used to resolve the handler.
func (*JSONResolver) Handle ¶
func (r *JSONResolver) Handle(ctx context.Context, msg []byte, rw ResponseWriter) error
type Logger ¶
type Logger interface {
Printf(format string, v ...interface{})
}
func DefaultLogger ¶
func DefaultLogger() Logger
type Message ¶
type Message struct { Message []byte // contains filtered or unexported fields }
Message is a message that can be sent to a connection. It is recommended to use the NewTextMessage, NewBinaryMessage and NewCloseMessage functions to create a Message.
func NewBinaryMessage ¶
func NewCloseMessage ¶
func NewCloseMessage() Message
func NewTextMessage ¶
type Middleware ¶
type Resolver ¶
type Resolver interface { // Handle resolves a message to a handler and returns the result of the handler. // If the message cannot be resolved, an error is returned. Handle(ctx context.Context, msg []byte, rw ResponseWriter) error }
Resolver is used to resolve a message to a handler.
type ResponseWriter ¶
type ResponseWriter interface { // WriteMessage writes a message to the connection. // If the message type is 0, it is set to websocket.TextMessage. // If the message type is not websocket.TextMessage, websocket.BinaryMessage or websocket.CloseMessage, an error is returned. WriteMessage(msg Message) error }