Documentation
¶
Index ¶
- Variables
- type ActionJSON
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) Listen(ctx context.Context)
- func (c *Conn) OnActionMessage(f func(*Conn, action.ActionMessage))
- func (c *Conn) OnClosed(f func(*Conn))
- func (c *Conn) OnError(f func(*Conn, error))
- func (c *Conn) Request() *http.Request
- func (c *Conn) Send(m event.Event)
- func (c *Conn) UserID() uint64
- type Handler
- type Server
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyClosed = errors.New("already closed")
Functions ¶
This section is empty.
Types ¶
type ActionJSON ¶
type ActionJSON struct { ActionName action.Action `json:"action"` Data action.AnyMessage `json:"data"` }
ActionJSON is a data-transfer-object which is sent by json the client connection.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is end-point for reading/writing messages from/to websocket. One Conn corresponds to one browser-side client.
func (*Conn) Close ¶
Close stops Listen() immediately. closed Conn never listen any message. it returns ErrAlreadyClosed when the Conn is already closed otherwise nil.
func (*Conn) Listen ¶
Listen starts handling reading/writing websocket. it blocks until websocket is closed or context is done.
when Listen() ends, Conn is closed.
func (*Conn) OnActionMessage ¶
func (c *Conn) OnActionMessage(f func(*Conn, action.ActionMessage))
set callback function to handle the event for a message is received. the callback function may be called asynchronously.
func (*Conn) OnClosed ¶
set callback function to handle the event for the connection is closed . the callback function may be called asynchronously.
func (*Conn) OnError ¶
set callback function to handle the event for the connection gets error. the callback function may be called asynchronously.
type Server ¶
type Server struct { // Handler for the Conn type in this package. Handler Handler // contains filtered or unexported fields }
Server serves Conn, wrapper for websocket Connetion, for each HTTP request. It implements http.Handler interface.
func NewServer ¶
NewServer creates the server which serves websocket Connection and providing customizable handler for that connection.
func NewServerFunc ¶
NewServerFunc is wrapper function for the NewServer so that given function need not to cast to Handler type.
func (*Server) ServeHTTPWithUserID ¶
ServeHTTPWithUserID is similar with the http.Handler except that it requires userID to specify the which user connects.