Documentation ¶
Index ¶
- Constants
- func NewMessageId() string
- type Client
- func (client *Client) AddClientRequestFilterFunc(filter func(context *ClientContext) bool)
- func (client *Client) AddClientResponseFilterFunc(filter func(context *ClientContext) bool)
- func (client *Client) AddServerRequestFilterFunc(filter func(context *ClientContext) bool)
- func (client *Client) AddServerResponseFilterFunc(filter func(context *ClientContext) bool)
- func (client *Client) CloseConnection()
- func (client *Client) IsActiveStatus() bool
- func (client *Client) RegisterProcessFunc(processFuncName string, processFunc func(context *ClientContext))
- func (client *Client) SendMessage(process string, header map[string]string, body string, ...)
- func (client *Client) SendMessageAsync(process string, header map[string]string, body string) (*ClientContext, error)
- func (client *Client) SetDefaultProcessFunc(fun func(context *ClientContext))
- func (client *Client) SetPongTime(pongTime int64)
- func (client *Client) SetReadBeforeFunc(fun func(data []byte) []byte)
- func (client *Client) SetRequestCommonHeader(header map[string]string)
- func (client *Client) SetRequestTimeout(timeout int64)
- func (client *Client) SetResponseCommonHeader(header map[string]string)
- func (client *Client) SetWriteBeforeFunc(fun func(data []byte) []byte)
- func (client *Client) ShowPongLogs(isShowPongLogs bool)
- type ClientConnChannel
- func (channel *ClientConnChannel) CloseConnection(code int, message string)
- func (channel *ClientConnChannel) SendMessage(process string, header map[string]string, body string, ...)
- func (channel *ClientConnChannel) SendMessageSync(process string, header map[string]string, body string) (*ServerContext, error)
- type ClientContext
- type ClientRequestCallback
- type Server
- func (server *Server) AddClientRequestFilterFunc(filter func(context *ServerContext) bool)
- func (server *Server) AddClientResponseFilterFunc(filter func(context *ServerContext) bool)
- func (server *Server) AddConnCloseEventFunc(fun func(channel *ClientConnChannel))
- func (server *Server) AddConnOpenEventFunc(fun func(channel *ClientConnChannel))
- func (server *Server) AddServerRequestFilterFunc(filter func(context *ServerContext) bool)
- func (server *Server) AddServerResponseFilterFunc(filter func(context *ServerContext) bool)
- func (server *Server) GetAllClientChannel() map[string]*ClientConnChannel
- func (server *Server) GetClientChannel(name string) (*ClientConnChannel, error)
- func (server *Server) LauncherServer(path string, port int) error
- func (server *Server) RegisterProcessFunc(processFuncName string, processFunc func(context *ServerContext))
- func (server *Server) SetAuthorizationFunc(fun func(request *http.Request) (string, bool))
- func (server *Server) SetDefaultProcessFunc(fun func(context *ServerContext))
- func (server *Server) SetReadBeforeFunc(fun func(data []byte) []byte)
- func (server *Server) SetRequestCommonHeader(header map[string]string)
- func (server *Server) SetRequestTimeout(timeout int64)
- func (server *Server) SetResponseCommonHeader(header map[string]string)
- func (server *Server) SetWebsocketUpgrader(upgrader *websocket.Upgrader)
- func (server *Server) SetWriteBeforeFunc(fun func(data []byte) []byte)
- func (server *Server) ShowPongLogs(isShowPongLogs bool)
- func (server *Server) UpgradeHttp(writer http.ResponseWriter, request *http.Request)
- type ServerContext
- type ServerRequestCallback
- type SocketRequest
- type SocketResponse
Constants ¶
const ( PongProcessName = "Health" PongProcessTime = 4500 PongProcessSuccess = 0 RequestTimeoutCode = -500 RequestTimeoutMsg = "timeout" RequestDefaultTimeout = int64(60 * 1000) )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶ added in v1.0.1
type Client struct { Conn *websocket.Conn // 连接实例 Name string // 连接名称 Url string // 连接路径 // contains filtered or unexported fields }
func (*Client) AddClientRequestFilterFunc ¶ added in v1.0.4
func (client *Client) AddClientRequestFilterFunc(filter func(context *ClientContext) bool)
AddClientRequestFilterFunc 添加Request过滤器函数(仅针对客户端对服务端的请求有效)
func (*Client) AddClientResponseFilterFunc ¶ added in v1.0.4
func (client *Client) AddClientResponseFilterFunc(filter func(context *ClientContext) bool)
AddClientResponseFilterFunc 添加Response过滤器函数(仅针对服务端对客户端的响应有效)
func (*Client) AddServerRequestFilterFunc ¶ added in v1.0.4
func (client *Client) AddServerRequestFilterFunc(filter func(context *ClientContext) bool)
AddServerRequestFilterFunc 添加Request过滤器函数(仅针对服务端对客户端的请求有效)
func (*Client) AddServerResponseFilterFunc ¶ added in v1.0.4
func (client *Client) AddServerResponseFilterFunc(filter func(context *ClientContext) bool)
AddServerResponseFilterFunc 添加Response过滤器函数(仅针对客户端对服务端的响应有效)
func (*Client) CloseConnection ¶ added in v1.0.4
func (client *Client) CloseConnection()
CloseConnection 关闭连接
func (*Client) IsActiveStatus ¶ added in v1.0.4
IsActiveStatus 客户端是否活跃(即使当前连接是断开的但是系统会自动重连)
func (*Client) RegisterProcessFunc ¶ added in v1.0.4
func (client *Client) RegisterProcessFunc(processFuncName string, processFunc func(context *ClientContext))
RegisterProcessFunc 注册请求处理器(所有的业务应该在Process中处理)
func (*Client) SendMessage ¶ added in v1.0.4
func (*Client) SendMessageAsync ¶ added in v1.0.4
func (*Client) SetDefaultProcessFunc ¶ added in v1.0.4
func (client *Client) SetDefaultProcessFunc(fun func(context *ClientContext))
SetDefaultProcessFunc 默认Process函数
func (*Client) SetPongTime ¶ added in v1.0.4
SetPongTime 设置心跳间隔(毫秒)
func (*Client) SetReadBeforeFunc ¶ added in v1.0.4
SetReadBeforeFunc 消息接收之前处理函数
func (*Client) SetRequestCommonHeader ¶ added in v1.0.4
func (*Client) SetRequestTimeout ¶ added in v1.0.4
func (*Client) SetResponseCommonHeader ¶ added in v1.0.4
func (*Client) SetWriteBeforeFunc ¶ added in v1.0.4
SetWriteBeforeFunc 消息传送之前处理函数
func (*Client) ShowPongLogs ¶ added in v1.0.4
ShowPongLogs 显示心跳日志
type ClientConnChannel ¶ added in v1.0.4
type ClientConnChannel struct { ConnName string // 客户端名称 PongTime int64 // 心跳最新时间 ConnSocket *websocket.Conn // 连接对象 BindServer *Server // 绑定的服务 }
ClientConnChannel 封装一个客户端连接信息
func (*ClientConnChannel) CloseConnection ¶ added in v1.0.4
func (channel *ClientConnChannel) CloseConnection(code int, message string)
CloseConnection 关闭渠道(连接)
func (*ClientConnChannel) SendMessage ¶ added in v1.0.4
func (channel *ClientConnChannel) SendMessage(process string, header map[string]string, body string, callback func(context *ServerContext))
SendMessage 发送消息(异步)
func (*ClientConnChannel) SendMessageSync ¶ added in v1.0.4
func (channel *ClientConnChannel) SendMessageSync(process string, header map[string]string, body string) (*ServerContext, error)
SendMessageSync 发送消息(同步)
type ClientContext ¶ added in v1.0.4
type ClientContext struct { Client *Client `json:"client"` Request *SocketRequest `json:"request"` Response *SocketResponse `json:"response"` Extra interface{} `json:"extra"` Error error `json:"error"` }
ClientContext 封装请求上下文信息
type ClientRequestCallback ¶ added in v1.0.4
type ClientRequestCallback struct { Context *ClientContext `json:"context"` Callback func(ctx *ClientContext) `json:"callback"` CreateTime int64 `json:"create_time"` }
ClientRequestCallback 封装request异步回调的函数信息
type Server ¶ added in v1.0.1
type Server struct { Name string // 服务名 // contains filtered or unexported fields }
func (*Server) AddClientRequestFilterFunc ¶ added in v1.0.1
func (server *Server) AddClientRequestFilterFunc(filter func(context *ServerContext) bool)
AddClientRequestFilterFunc 添加Request过滤器函数(仅针对客户端对服务端的请求有效)
func (*Server) AddClientResponseFilterFunc ¶ added in v1.0.1
func (server *Server) AddClientResponseFilterFunc(filter func(context *ServerContext) bool)
AddClientResponseFilterFunc 添加Response过滤器函数(仅针对服务端对客户端的响应有效)
func (*Server) AddConnCloseEventFunc ¶ added in v1.0.4
func (server *Server) AddConnCloseEventFunc(fun func(channel *ClientConnChannel))
AddConnCloseEventFunc 设置连接监听
func (*Server) AddConnOpenEventFunc ¶ added in v1.0.4
func (server *Server) AddConnOpenEventFunc(fun func(channel *ClientConnChannel))
AddConnOpenEventFunc 设置连接监听
func (*Server) AddServerRequestFilterFunc ¶ added in v1.0.1
func (server *Server) AddServerRequestFilterFunc(filter func(context *ServerContext) bool)
AddServerRequestFilterFunc 添加Request过滤器函数(仅针对服务端对客户端的请求有效)
func (*Server) AddServerResponseFilterFunc ¶ added in v1.0.1
func (server *Server) AddServerResponseFilterFunc(filter func(context *ServerContext) bool)
AddServerResponseFilterFunc 添加Response过滤器函数(仅针对客户端对服务端的响应有效)
func (*Server) GetAllClientChannel ¶ added in v1.0.4
func (server *Server) GetAllClientChannel() map[string]*ClientConnChannel
GetAllClientChannel 获取全部连接
func (*Server) GetClientChannel ¶ added in v1.0.4
func (server *Server) GetClientChannel(name string) (*ClientConnChannel, error)
GetClientChannel 获取连接(name 为 authorizationFunc 的返回值)
func (*Server) LauncherServer ¶ added in v1.0.4
LauncherServer 启动服务
func (*Server) RegisterProcessFunc ¶ added in v1.0.4
func (server *Server) RegisterProcessFunc(processFuncName string, processFunc func(context *ServerContext))
RegisterProcessFunc 注册请求处理器(所有的业务应该在Process中处理)
func (*Server) SetAuthorizationFunc ¶ added in v1.0.1
SetAuthorizationFunc 设置授权处理函数,返回: 连接名称/认证结果
func (*Server) SetDefaultProcessFunc ¶ added in v1.0.4
func (server *Server) SetDefaultProcessFunc(fun func(context *ServerContext))
SetDefaultProcessFunc 默认Process函数
func (*Server) SetReadBeforeFunc ¶ added in v1.0.4
SetReadBeforeFunc 设置 websocket.Upgrader
func (*Server) SetRequestCommonHeader ¶ added in v1.0.1
SetRequestCommonHeader 设置 Common Request Header
func (*Server) SetRequestTimeout ¶ added in v1.0.4
SetRequestTimeout 设置超时
func (*Server) SetResponseCommonHeader ¶ added in v1.0.4
SetResponseCommonHeader 设置 Common Request Header
func (*Server) SetWebsocketUpgrader ¶ added in v1.0.4
SetWebsocketUpgrader 消息接收之前处理函数
func (*Server) SetWriteBeforeFunc ¶ added in v1.0.4
SetWriteBeforeFunc 消息传送之前处理函数
func (*Server) ShowPongLogs ¶ added in v1.0.4
ShowPongLogs 显示心跳日志
func (*Server) UpgradeHttp ¶ added in v1.0.4
func (server *Server) UpgradeHttp(writer http.ResponseWriter, request *http.Request)
UpgradeHttp 将http转为socket(兼容使用gin等第三方web框架)
type ServerContext ¶ added in v1.0.4
type ServerContext struct { Channel *ClientConnChannel `json:"channel"` Request *SocketRequest `json:"request"` Response *SocketResponse `json:"response"` Error error `json:"error"` }
ServerContext 封装请求上下文信息
type ServerRequestCallback ¶ added in v1.0.4
type ServerRequestCallback struct { Context *ServerContext `json:"context"` Callback func(ctx *ServerContext) `json:"callback"` CreateTime int64 `json:"create_time"` }
ServerRequestCallback 封装request异步回调的函数信息
type SocketRequest ¶
type SocketRequest struct { Uid string `json:"U"` // 消息唯一ID Process string `json:"P"` // 处理器 Header map[string]string `json:"H"` // 数据头 Body string `json:"B"` // 数据体(需要进行编码后传输) }
SocketRequest {"U":"","P":"","H":{},"B":""}
func RequestNew ¶ added in v1.0.4
func RequestNew(process string, header map[string]string, body string) *SocketRequest
RequestNew 新建一个请求体
type SocketResponse ¶
type SocketResponse struct { Uid string `json:"U"` // 消息唯一ID Code int `json:"C"` // 业务状态 Message string `json:"M"` // 业务说明 Header map[string]string `json:"H"` // 数据头 Body string `json:"B"` // 数据体(需要进行编码后传输) }
SocketResponse {"U":"","C":"","M":"","H":{},"B":""}
func ResponseNew ¶ added in v1.0.4
ResponseNew 新建一个响应体