Documentation ¶
Overview ¶
Simple tools for nhooyr websockets with intuitive API (in golang)
Index ¶
- Variables
- type CloseHandler
- type Connection
- func (c *Connection) Close(status websocket.StatusCode, reason string) error
- func (c *Connection) OnClose(h CloseHandler)
- func (c *Connection) OnError(h ErrorHandler)
- func (c *Connection) OnMessage(h MessageHandler)
- func (c *Connection) OnMessageBuffer(h MessageBufferHandler)
- func (c *Connection) OnMessageReader(h MessageReaderHandler)
- func (c *Connection) UUID() string
- func (c *Connection) WS() *websocket.Conn
- func (c *Connection) Write(ctx context.Context, typ websocket.MessageType, data []byte) error
- func (c *Connection) WriteJSON(ctx context.Context, v interface{}) error
- type ErrorHandler
- type MessageBufferHandler
- type MessageHandler
- type MessageReaderHandler
- type Payload
Constants ¶
This section is empty.
Variables ¶
View Source
var ( Accept = func(w http.ResponseWriter, r *http.Request, opts *websocket.AcceptOptions) (*Connection, error) { conn, err := websocket.Accept(w, r, opts) if err != nil { return nil, err } return NewConnection(conn), nil } Dial = func(ctx context.Context, u string, opts *websocket.DialOptions) (*Connection, error) { conn, _, err := websocket.Dial(ctx, u, opts) if err != nil { return nil, err } return NewConnection(conn), nil } )
View Source
var ( EmptyCloseHandler = CloseHandler(func(connection *Connection, code websocket.StatusCode, reason string) {}) EmptyErrorHandler = ErrorHandler(func(connection *Connection, err error) {}) )
Functions ¶
This section is empty.
Types ¶
type CloseHandler ¶
type CloseHandler func(conn *Connection, code websocket.StatusCode, reason string)
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
func NewConnection ¶
func NewConnection(conn *websocket.Conn) *Connection
func (*Connection) Close ¶
func (c *Connection) Close(status websocket.StatusCode, reason string) error
func (*Connection) OnClose ¶
func (c *Connection) OnClose(h CloseHandler)
func (*Connection) OnError ¶
func (c *Connection) OnError(h ErrorHandler)
func (*Connection) OnMessage ¶
func (c *Connection) OnMessage(h MessageHandler)
func (*Connection) OnMessageBuffer ¶
func (c *Connection) OnMessageBuffer(h MessageBufferHandler)
func (*Connection) OnMessageReader ¶
func (c *Connection) OnMessageReader(h MessageReaderHandler)
func (*Connection) UUID ¶
func (c *Connection) UUID() string
func (*Connection) WS ¶
func (c *Connection) WS() *websocket.Conn
func (*Connection) Write ¶
func (c *Connection) Write(ctx context.Context, typ websocket.MessageType, data []byte) error
type ErrorHandler ¶
type ErrorHandler func(conn *Connection, err error)
type MessageBufferHandler ¶
type MessageBufferHandler func(conn *Connection, mtype websocket.MessageType, data *bytes.Buffer)
type MessageHandler ¶
type MessageHandler func(conn *Connection, mtype websocket.MessageType, data Payload)
type MessageReaderHandler ¶
type MessageReaderHandler func(conn *Connection, mtype websocket.MessageType, data io.Reader)
Click to show internal directories.
Click to hide internal directories.