Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientSrv ¶
type ClientSrv struct { Engine *tcp.Client Emitter *emit.Emitter // contains filtered or unexported fields }
func (*ClientSrv) On ¶
func (cs *ClientSrv) On(cmd string, h func(*TCPResponse))
On 监听服务器响应数据,每当服务器有数据发送过来,都会以 cmd 为事件名触发监听函数
type Context ¶
type Context struct { Values map[string]interface{} // 该会话注册的值 CMD string // 命令名称 Seqno string // 请求唯一标识符 RawData json.RawMessage // 请求原始数据 data SessionID uint64 // 会话ID Socket *tcp.Conn // 长连接对象 RawMessage *tcp.Message // 原始消息对象 Engine *tcp.Server // 引擎 Server *ServerSrv // 服务器对象 Payload []byte // 请求原始消息报文 Request *TCPRequest // 已解析的请求数据 Response *TCPResponse // 响应数据 // contains filtered or unexported fields }
Context 请求上下文
type ServerSrv ¶
type ServerSrv struct { Engine *tcp.Server Config *tcp.Config Session map[uint64]map[string]interface{} // map[sid]SessionData // contains filtered or unexported fields }
func (*ServerSrv) Handle ¶
func (srv *ServerSrv) Handle(cmd string, handlers ...TCPHandler)
Handle 注册 CMD 路由监听器
type TCPClientRequest ¶
type TCPClientRequest struct { CMD string `json:"cmd"` Seqno string `json:"seqno"` Data interface{} `json:"data"` }
WSRequest 请求数据
type TCPHandler ¶
type TCPHandler func(*Context)
type TCPRequest ¶
type TCPRequest struct { CMD string `json:"cmd"` Seqno string `json:"seqno"` Data json.RawMessage `json:"data"` }
WSRequest 请求数据
func (*TCPRequest) BindJSON ¶
func (r *TCPRequest) BindJSON(v interface{}) error
func (*TCPRequest) SetJSON ¶
func (r *TCPRequest) SetJSON(v interface{}) (err error)
type TCPResponse ¶
type TCPResponse struct { CMD string `json:"cmd"` Seqno string `json:"seqno"` Status int `json:"status"` Msg string `json:"msg"` Data json.RawMessage `json:"data"` }
WSResponse 响应数据
func (*TCPResponse) BindJSON ¶
func (r *TCPResponse) BindJSON(v interface{}) error
func (*TCPResponse) SetJSON ¶
func (r *TCPResponse) SetJSON(v interface{}) (err error)
Click to show internal directories.
Click to hide internal directories.