Documentation ¶
Index ¶
- type Client
- type Connection
- type ConnectionEvents
- func (e *ConnectionEvents) AfterRequest(tx *storage.Transaction) (err error)
- func (e *ConnectionEvents) BeforeRequest(ctx route.RequestContext, msg *JSONMessage) (cancelConnection bool, err error)
- func (e *ConnectionEvents) CreateRequest(conn *Connection, tx *storage.Transaction) (r route.Request)
- func (e *ConnectionEvents) NewConnection(c *Connection, uctx UpgradeContext) (err error)
- func (e *ConnectionEvents) OnAfterRequest(fn OnAfterRequest)
- func (e *ConnectionEvents) OnBeforeRequest(fn OnBeforeRequest)
- func (e *ConnectionEvents) OnCreateRequest(fn OnCreateRequest)
- func (e *ConnectionEvents) OnNewConnection(fn OnNewConnection)
- type ConnectionHandler
- type GetHandlerFunc
- type HTTPContext
- type JSONMessage
- type Message
- type OnAfterRequest
- type OnBeforeRequest
- type OnCreateRequest
- type OnNewConnection
- type RequestContext
- type Server
- type ServerConfig
- type UpgradeContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { ConnectionHandler WriteWait time.Duration }
Client that is able to connect to a websocket server
func (*Client) BroadcastJSON ¶
func (c *Client) BroadcastJSON(name string, t route.Type, data interface{}, filter func(*Connection) bool)
BroadcastJSON broadcast data to all connections (can be filtered)
type Connection ¶
type Connection struct { Context route.RequestContext // contains filtered or unexported fields }
Connection interface
func NewClientConnection ¶
func NewClientConnection(ch ConnectionHandler, conn *gorilla.Conn, lang *language.Tag) (c *Connection)
NewClientConnection instance creation
func NewServerConnection ¶
func NewServerConnection(ch ConnectionHandler, conn *gorilla.Conn, lang *language.Tag) (c *Connection)
NewServerConnection instance creation
type ConnectionEvents ¶
type ConnectionEvents struct {
// contains filtered or unexported fields
}
ConnectionEvents event handlers for connections
func (*ConnectionEvents) AfterRequest ¶
func (e *ConnectionEvents) AfterRequest(tx *storage.Transaction) (err error)
AfterRequest hook registration
func (*ConnectionEvents) BeforeRequest ¶
func (e *ConnectionEvents) BeforeRequest(ctx route.RequestContext, msg *JSONMessage) (cancelConnection bool, err error)
BeforeRequest hook registration
func (*ConnectionEvents) CreateRequest ¶
func (e *ConnectionEvents) CreateRequest(conn *Connection, tx *storage.Transaction) (r route.Request)
CreateRequest event trigger
func (*ConnectionEvents) NewConnection ¶
func (e *ConnectionEvents) NewConnection(c *Connection, uctx UpgradeContext) (err error)
NewConnection event trigger
func (*ConnectionEvents) OnAfterRequest ¶
func (e *ConnectionEvents) OnAfterRequest(fn OnAfterRequest)
OnAfterRequest hook registration
func (*ConnectionEvents) OnBeforeRequest ¶
func (e *ConnectionEvents) OnBeforeRequest(fn OnBeforeRequest)
OnBeforeRequest hook registration
func (*ConnectionEvents) OnCreateRequest ¶
func (e *ConnectionEvents) OnCreateRequest(fn OnCreateRequest)
OnCreateRequest hook registration
func (*ConnectionEvents) OnNewConnection ¶
func (e *ConnectionEvents) OnNewConnection(fn OnNewConnection)
OnNewConnection hook registration
type ConnectionHandler ¶
type ConnectionHandler struct { service.Container route.Grouper ConnectionEvents // contains filtered or unexported fields }
ConnectionHandler base type
func CreateConnectionHandler ¶
func CreateConnectionHandler(c service.Container, isServer bool) (h ConnectionHandler)
CreateConnectionHandler helper
func (*ConnectionHandler) GetHandler ¶
func (ch *ConnectionHandler) GetHandler(msg *JSONMessage) (middleware []route.Middleware, h route.Handler)
GetHandler for a request
type GetHandlerFunc ¶
type GetHandlerFunc func(data *JSONMessage) (middleware []route.Middleware, h route.Handler)
GetHandlerFunc :
type HTTPContext ¶
type HTTPContext struct { Writer netHttp.ResponseWriter Request *netHttp.Request ResponseHeader netHttp.Header }
HTTPContext for http upgrade
type JSONMessage ¶
type JSONMessage struct { Route string `json:"r"` Type route.Type `json:"t"` Payload string `json:"p"` AuthToken string `json:"a,omitempty"` }
JSONMessage is sent via a websocket
type Message ¶
type Message struct { Name string T route.Type Data interface{} Filter func(*Connection) bool }
Message to be sent via a websocket connection
type OnAfterRequest ¶
type OnAfterRequest func(tx *storage.Transaction) (err error)
OnAfterRequest hook
type OnBeforeRequest ¶
type OnBeforeRequest func(ctx route.RequestContext, msg *JSONMessage) (cancelConnection bool, err error)
OnBeforeRequest hook
type OnCreateRequest ¶
type OnCreateRequest func(conn *Connection, tx *storage.Transaction) (r route.Request)
OnCreateRequest hook
type OnNewConnection ¶
type OnNewConnection func(c *Connection, uctx UpgradeContext) (err error)
OnNewConnection hook
type RequestContext ¶
type RequestContext struct {
route.BaseRequestContext
}
RequestContext of a connection
type Server ¶
type Server struct { ConnectionHandler // contains filtered or unexported fields }
Server for a websocket api
func NewServer ¶
func NewServer(config *ServerConfig, co service.Container) (s *Server, err error)
NewServer instance creation
func (*Server) BroadcastJSON ¶
func (s *Server) BroadcastJSON(name string, t route.Type, data interface{}, filter func(*Connection) bool)
BroadcastJSON broadcast data to all connections (can be filtered)
func (*Server) UpgradeConnection ¶
func (s *Server) UpgradeConnection(ctx UpgradeContext) (err error)
UpgradeConnection http to a websocket connection
func (*Server) UpgradeHandler ¶
func (s *Server) UpgradeHandler(server *netHttp.Server) route.HandlerGenerator
UpgradeHandler returns a handler that upgrades a http connection to a websocket connection that is handled by this server
type ServerConfig ¶
type ServerConfig struct { Upgrader *gorilla.Upgrader WriteWait time.Duration PongWait time.Duration PingInterval time.Duration MaxMessageSize int64 }
ServerConfig of the api
type UpgradeContext ¶
type UpgradeContext interface { HTTPContext() (ctx *HTTPContext) Language() (lang *language.Tag) }
UpgradeContext is used to upgrade http to websocket