Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct { Values map[string]interface{} // 该会话注册的值 CMD string // 命令名称 Seqno string // 请求唯一标识符 RawData json.RawMessage // 请求原始数据 data SessionID uint64 // 会话ID Socket *websocket.Conn // 长连接对象 RawMessage *websocket.Message // 原始消息对象 Engine *websocket.WS // 引擎 Server *WebsocketServer // 服务器对象 Payload []byte // 请求原始消息报文 RequestData *WSRequest // 已解析的请求数据 ResponseData *WSResponse // 响应数据 // contains filtered or unexported fields }
Context 请求上下文
type WSRequest ¶
type WSRequest struct { CMD string `json:"cmd"` Seqno string `json:"seqno"` Data json.RawMessage `json:"data"` }
WSRequest 请求数据
type WSResponse ¶
type WSResponse struct { CMD string `json:"cmd"` Seqno string `json:"seqno"` Status int `json:"status"` Msg string `json:"msg"` Data interface{} `json:"data"` }
WSResponse 响应数据
type WebsocketServer ¶
type WebsocketServer struct { Engine *websocket.WS Config *websocket.Config Session map[uint64]map[string]interface{} // map[sid]SessionData // contains filtered or unexported fields }
WebsocketServer 服务器
func (*WebsocketServer) Handle ¶
func (ws *WebsocketServer) Handle(cmd string, handlers ...WSHandler)
Handle 注册 CMD 路由监听器
func (*WebsocketServer) Push ¶
func (ws *WebsocketServer) Push(sid uint64, data *WSResponse) error
Push 服务器推送消息到客户端
func (*WebsocketServer) UseRequest ¶
func (ws *WebsocketServer) UseRequest(h WSHandler)
UseRequest 请求中间件
func (*WebsocketServer) UseResponse ¶
func (ws *WebsocketServer) UseResponse(h WSHandler)
UseResponse 响应中间件
Click to show internal directories.
Click to hide internal directories.