Documentation ¶
Overview ¶
PoolHandler is handler which may be useful at the projects where websocket connections are divided into a groups (pools) with access to common data
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PoolHandler ¶
func PoolHandler(poolMgr PoolManager, connMgr ConnManager, verifier RequestVerifier) http.Handler
PoolHandler returns WS handler which receives websocket requests and merges connection goroutines in a pools (groups) with common data. poolMgr is a storage of groups and connections. poolMgr divides handled connections into groups, stores common group data and passes common data to goroutines for processing ws connections. connMgr contains handler for processing of ws connection. connMgr gets common group and ws connection. verifier must verify connections. If was passed nil instead verifier connections will not verified
Types ¶
type ConnManager ¶
type ConnManager interface { // Handle handles connections using passed common environment data Handle(ws *websocket.Conn, data Environment) error // HandleError processes an errors HandleError(ws *websocket.Conn, err error) }
ConnManager contains methods for processing websocket connections with passed common group data
type Environment ¶
type Environment interface{}
Environment is a common data for ws connections in one pool (group)
type PoolManager ¶
type PoolManager interface { // AddConn creates connection to a pool and returns environment data AddConn(ws *websocket.Conn) (Environment, error) // DelConn removes passed connection from a pool if it exists in pool DelConn(ws *websocket.Conn) error }
PoolManager is common interface for a structures which merge websocket connections in a pools (groups) with access to common data
type RequestVerifier ¶
RequestVerifier verifies requests. It has to verify a request data such a passed hashes, certificates, remote addr, token, passed headers or something else