Documentation ¶
Index ¶
- Constants
- Variables
- func HeatBeatDefaultHandle(req ziface.IRequest)
- func NewClient(ip string, port int, opts ...ClientOption) ziface.IClient
- func NewDefaultRouterSlicesServer(opts ...Option) ziface.IServer
- func NewFuncRequest(conn ziface.IConnection, callFunc func()) ziface.IRequest
- func NewHeartbeatChecker(interval time.Duration) ziface.IHeartbeatChecker
- func NewRequest(conn ziface.IConnection, msg ziface.IMessage) ziface.IRequest
- func NewServer(opts ...Option) ziface.IServer
- func NewTLSClient(ip string, port int, opts ...ClientOption) ziface.IClient
- func NewUserConfDefaultRouterSlicesServer(config *zconf.Config, opts ...Option) ziface.IServer
- func NewUserConfServer(config *zconf.Config, opts ...Option) ziface.IServer
- func NewWsClient(ip string, port int, opts ...ClientOption) ziface.IClient
- func RouterRecovery(request ziface.IRequest)
- func RouterTime(request ziface.IRequest)
- type BaseRouter
- type Client
- func (c *Client) AddInterceptor(interceptor ziface.IInterceptor)
- func (c *Client) AddRouter(msgID uint32, router ziface.IRouter)
- func (c *Client) Conn() ziface.IConnection
- func (c *Client) GetErrChan() chan error
- func (c *Client) GetLengthField() *ziface.LengthField
- func (c *Client) GetMsgHandler() ziface.IMsgHandle
- func (c *Client) GetName() string
- func (c *Client) GetOnConnStart() func(ziface.IConnection)
- func (c *Client) GetOnConnStop() func(ziface.IConnection)
- func (c *Client) GetPacket() ziface.IDataPack
- func (c *Client) Restart()
- func (c *Client) SetDecoder(decoder ziface.IDecoder)
- func (c *Client) SetName(name string)
- func (c *Client) SetOnConnStart(hookFunc func(ziface.IConnection))
- func (c *Client) SetOnConnStop(hookFunc func(ziface.IConnection))
- func (c *Client) SetPacket(packet ziface.IDataPack)
- func (c *Client) Start()
- func (c *Client) StartHeartBeat(interval time.Duration)
- func (c *Client) StartHeartBeatWithOption(interval time.Duration, option *ziface.HeartBeatOption)
- func (c *Client) Stop()
- type ClientOption
- type ConnManager
- func (connMgr *ConnManager) Add(conn ziface.IConnection)
- func (connMgr *ConnManager) ClearConn()
- func (connMgr *ConnManager) Get(connID uint64) (ziface.IConnection, error)
- func (connMgr *ConnManager) Get2(strConnId string) (ziface.IConnection, error)
- func (connMgr *ConnManager) GetAllConnID() []uint64
- func (connMgr *ConnManager) GetAllConnIdStr() []string
- func (connMgr *ConnManager) Len() int
- func (connMgr *ConnManager) Range(cb func(uint64, ziface.IConnection, interface{}) error, args interface{}) (err error)
- func (connMgr *ConnManager) Range2(cb func(string, ziface.IConnection, interface{}) error, args interface{}) (err error)
- func (connMgr *ConnManager) Remove(conn ziface.IConnection)
- type Connection
- func (c *Connection) Context() context.Context
- func (c *Connection) GetConnID() uint64
- func (c *Connection) GetConnIdStr() string
- func (c *Connection) GetConnection() net.Conn
- func (c *Connection) GetMsgHandler() ziface.IMsgHandle
- func (c *Connection) GetName() string
- func (c *Connection) GetProperty(key string) (interface{}, error)
- func (c *Connection) GetTCPConnection() net.Conndeprecated
- func (c *Connection) GetWorkerID() uint32
- func (c *Connection) GetWsConn() *websocket.Conn
- func (c *Connection) IsAlive() bool
- func (c *Connection) LocalAddr() net.Addr
- func (c *Connection) LocalAddrString() string
- func (c *Connection) RemoteAddr() net.Addr
- func (c *Connection) RemoteAddrString() string
- func (c *Connection) RemoveProperty(key string)
- func (c *Connection) Send(data []byte) error
- func (c *Connection) SendBuffMsg(msgID uint32, data []byte) error
- func (c *Connection) SendMsg(msgID uint32, data []byte) error
- func (c *Connection) SendToQueue(data []byte) error
- func (c *Connection) SetHeartBeat(checker ziface.IHeartbeatChecker)
- func (c *Connection) SetProperty(key string, value interface{})
- func (c *Connection) Start()
- func (c *Connection) StartReader()
- func (c *Connection) StartWriter()
- func (c *Connection) Stop()
- type GroupRouter
- type HeartbeatChecker
- func (h *HeartbeatChecker) BindConn(conn ziface.IConnection)
- func (h *HeartbeatChecker) BindRouter(msgID uint32, router ziface.IRouter)
- func (h *HeartbeatChecker) BindRouterSlices(msgID uint32, handlers ...ziface.RouterHandler)
- func (h *HeartbeatChecker) Clone() ziface.IHeartbeatChecker
- func (h *HeartbeatChecker) MsgID() uint32
- func (h *HeartbeatChecker) Router() ziface.IRouter
- func (h *HeartbeatChecker) RouterSlices() []ziface.RouterHandler
- func (h *HeartbeatChecker) SendHeartBeatMsg() error
- func (h *HeartbeatChecker) SetHeartbeatFunc(beatFunc ziface.HeartBeatFunc)
- func (h *HeartbeatChecker) SetHeartbeatMsgFunc(f ziface.HeartBeatMsgFunc)
- func (h *HeartbeatChecker) SetOnRemoteNotAlive(f ziface.OnRemoteNotAlive)
- func (h *HeartbeatChecker) Start()
- func (h *HeartbeatChecker) Stop()
- type HeatBeatDefaultRouter
- type KcpConnection
- func (c *KcpConnection) Context() context.Context
- func (c *KcpConnection) GetConnID() uint64
- func (c *KcpConnection) GetConnIdStr() string
- func (c *KcpConnection) GetConnection() net.Conn
- func (c *KcpConnection) GetMsgHandler() ziface.IMsgHandle
- func (c *KcpConnection) GetName() string
- func (c *KcpConnection) GetProperty(key string) (interface{}, error)
- func (c *KcpConnection) GetTCPConnection() net.Conndeprecated
- func (c *KcpConnection) GetWorkerID() uint32
- func (c *KcpConnection) GetWsConn() *websocket.Conn
- func (c *KcpConnection) IsAlive() bool
- func (c *KcpConnection) LocalAddr() net.Addr
- func (c *KcpConnection) LocalAddrString() string
- func (c *KcpConnection) RemoteAddr() net.Addr
- func (c *KcpConnection) RemoteAddrString() string
- func (c *KcpConnection) RemoveProperty(key string)
- func (c *KcpConnection) Send(data []byte) error
- func (c *KcpConnection) SendBuffMsg(msgID uint32, data []byte) error
- func (c *KcpConnection) SendMsg(msgID uint32, data []byte) error
- func (c *KcpConnection) SendToQueue(data []byte) error
- func (c *KcpConnection) SetHeartBeat(checker ziface.IHeartbeatChecker)
- func (c *KcpConnection) SetProperty(key string, value interface{})
- func (c *KcpConnection) Start()
- func (c *KcpConnection) StartReader()
- func (c *KcpConnection) StartWriter()
- func (c *KcpConnection) Stop()
- type MsgHandle
- func (mh *MsgHandle) AddInterceptor(interceptor ziface.IInterceptor)
- func (mh *MsgHandle) AddRouter(msgID uint32, router ziface.IRouter)
- func (mh *MsgHandle) AddRouterSlices(msgId uint32, handler ...ziface.RouterHandler) ziface.IRouterSlices
- func (mh *MsgHandle) Execute(request ziface.IRequest)
- func (mh *MsgHandle) Group(start, end uint32, Handlers ...ziface.RouterHandler) ziface.IGroupRouterSlices
- func (mh *MsgHandle) Intercept(chain ziface.IChain) ziface.IcResp
- func (mh *MsgHandle) SendMsgToTaskQueue(request ziface.IRequest)
- func (mh *MsgHandle) StartOneWorker(workerID int, taskQueue chan ziface.IRequest)
- func (mh *MsgHandle) StartWorkerPool()
- func (mh *MsgHandle) Use(Handlers ...ziface.RouterHandler) ziface.IRouterSlices
- type Option
- type Request
- func (r *Request) Abort()
- func (r *Request) BindRouter(router ziface.IRouter)
- func (r *Request) BindRouterSlices(handlers []ziface.RouterHandler)
- func (r *Request) Call()
- func (r *Request) GetConnection() ziface.IConnection
- func (r *Request) GetData() []byte
- func (r *Request) GetMessage() ziface.IMessage
- func (r *Request) GetMsgID() uint32
- func (r *Request) GetResponse() ziface.IcResp
- func (r *Request) Goto(step ziface.HandleStep)
- func (r *Request) RouterSlicesNext()
- func (r *Request) SetResponse(response ziface.IcResp)
- type RequestFunc
- type RouterSlices
- func (r *RouterSlices) AddHandler(msgId uint32, Handlers ...ziface.RouterHandler)
- func (r *RouterSlices) GetHandlers(MsgId uint32) ([]ziface.RouterHandler, bool)
- func (r *RouterSlices) Group(start, end uint32, Handlers ...ziface.RouterHandler) ziface.IGroupRouterSlices
- func (r *RouterSlices) Use(handles ...ziface.RouterHandler)
- type Server
- func (s *Server) AddInterceptor(interceptor ziface.IInterceptor)
- func (s *Server) AddRouter(msgID uint32, router ziface.IRouter)
- func (s *Server) AddRouterSlices(msgID uint32, router ...ziface.RouterHandler) ziface.IRouterSlices
- func (s *Server) GetConnMgr() ziface.IConnManager
- func (s *Server) GetHeartBeat() ziface.IHeartbeatChecker
- func (s *Server) GetLengthField() *ziface.LengthField
- func (s *Server) GetMsgHandler() ziface.IMsgHandle
- func (s *Server) GetOnConnStart() func(ziface.IConnection)
- func (s *Server) GetOnConnStop() func(ziface.IConnection)
- func (s *Server) GetPacket() ziface.IDataPack
- func (s *Server) Group(start, end uint32, Handlers ...ziface.RouterHandler) ziface.IGroupRouterSlices
- func (s *Server) ListenKcpConn()
- func (s *Server) ListenTcpConn()
- func (s *Server) ListenUDPConn()
- func (s *Server) ListenWebsocketConn()
- func (s *Server) Serve()
- func (s *Server) ServerName() string
- func (s *Server) SetDecoder(decoder ziface.IDecoder)
- func (s *Server) SetOnConnStart(hookFunc func(ziface.IConnection))
- func (s *Server) SetOnConnStop(hookFunc func(ziface.IConnection))
- func (s *Server) SetPacket(packet ziface.IDataPack)
- func (s *Server) SetWebsocketAuth(f func(r *http.Request) error)
- func (s *Server) Start()
- func (s *Server) StartConn(conn ziface.IConnection)
- func (s *Server) StartHeartBeat(interval time.Duration)
- func (s *Server) StartHeartBeatWithOption(interval time.Duration, option *ziface.HeartBeatOption)
- func (s *Server) Stop()
- func (s *Server) Use(Handlers ...ziface.RouterHandler) ziface.IRouterSlices
- type WsConnection
- func (c *WsConnection) Context() context.Context
- func (c *WsConnection) GetConnID() uint64
- func (c *WsConnection) GetConnIdStr() string
- func (c *WsConnection) GetConnection() net.Conn
- func (c *WsConnection) GetMsgHandler() ziface.IMsgHandle
- func (c *WsConnection) GetName() string
- func (c *WsConnection) GetProperty(key string) (interface{}, error)
- func (c *WsConnection) GetTCPConnection() net.Conndeprecated
- func (c *WsConnection) GetWorkerID() uint32
- func (c *WsConnection) GetWsConn() *websocket.Conn
- func (c *WsConnection) IsAlive() bool
- func (c *WsConnection) LocalAddr() net.Addr
- func (c *WsConnection) LocalAddrString() string
- func (c *WsConnection) RemoteAddr() net.Addr
- func (c *WsConnection) RemoteAddrString() string
- func (c *WsConnection) RemoveProperty(key string)
- func (c *WsConnection) Send(data []byte) error
- func (c *WsConnection) SendBuffMsg(msgID uint32, data []byte) error
- func (c *WsConnection) SendMsg(msgID uint32, data []byte) error
- func (c *WsConnection) SendToQueue(data []byte) error
- func (c *WsConnection) SetHeartBeat(checker ziface.IHeartbeatChecker)
- func (c *WsConnection) SetProperty(key string, value interface{})
- func (c *WsConnection) Start()
- func (c *WsConnection) StartReader()
- func (c *WsConnection) StartWriter()
- func (c *WsConnection) Stop()
Constants ¶
const ( // The number of stack frames to start tracing from // (开始追踪堆栈信息的层数) StackBegin = 3 // The number of stack frames to trace until the end // (追踪到最后的层数) StackEnd = 5 )
const ( PRE_HANDLE ziface.HandleStep = iota // PreHandle for pre-processing HANDLE // Handle for processing POST_HANDLE // PostHandle for post-processing HANDLE_OVER )
const ( // If the Worker goroutine pool is not started, a virtual WorkerID is assigned to the MsgHandler, which is 0, for metric counting // After starting the Worker goroutine pool, the ID of each worker is 0,1,2,3... // (如果不启动Worker协程池,则会给MsgHandler分配一个虚拟的WorkerID,这个workerID为0, 便于指标统计 // 启动了Worker协程池后,每个worker的ID为0,1,2,3...) WorkerIDWithoutWorkerPool int = 0 )
Variables ¶
var AcceptDelay *acceptDelay
Functions ¶
func HeatBeatDefaultHandle ¶
func NewDefaultRouterSlicesServer ¶
NewDefaultRouterSlicesServer creates a server handle with a default RouterRecovery processor. (创建一个默认自带一个Recover处理器的服务器句柄)
func NewFuncRequest ¶
func NewFuncRequest(conn ziface.IConnection, callFunc func()) ziface.IRequest
func NewHeartbeatChecker ¶
func NewHeartbeatChecker(interval time.Duration) ziface.IHeartbeatChecker
func NewRequest ¶
func NewTLSClient ¶
func NewTLSClient(ip string, port int, opts ...ClientOption) ziface.IClient
func NewUserConfDefaultRouterSlicesServer ¶
NewUserConfDefaultRouterSlicesServer creates a server handle with user-configured options and a default Recover handler. If the user does not wish to use the Use method, they should use NewUserConfServer instead. (创建一个用户配置的自带一个Recover处理器的服务器句柄,如果用户不希望Use这个方法,那么应该使用NewUserConfServer)
func NewUserConfServer ¶
NewUserConfServer creates a server handle using user-defined configuration (创建一个服务器句柄)
func NewWsClient ¶
func NewWsClient(ip string, port int, opts ...ClientOption) ziface.IClient
func RouterRecovery ¶
RouterRecovery If you use the server obtained from initializing with NewDefaultRouterSlicesServer method, this function will be included. It is used to catch any panics that occur during request handling and attempt to record the context information. (如果使用NewDefaultRouterSlicesServer方法初始化的获得的server将自带这个函数 作用是接收业务执行上产生的panic并且尝试记录现场信息)
func RouterTime ¶
RouterTime Simply accumulates the time taken by all the routing groups, but not enabled (简单累计所有路由组的耗时,不启用)
Types ¶
type BaseRouter ¶
type BaseRouter struct{}
BaseRouter is used as the base class when implementing a router. Depending on the needs, the methods of this base class can be overridden. (实现router时,先嵌入这个基类,然后根据需要对这个基类的方法进行重写)
type Client ¶
type Client struct { // Client Name 客户端的名称 Name string // IP of the target server to connect 目标链接服务器的IP Ip string // Port of the target server to connect 目标链接服务器的端口 Port int // Error channel ErrChan chan error // contains filtered or unexported fields }
func (*Client) AddInterceptor ¶
func (c *Client) AddInterceptor(interceptor ziface.IInterceptor)
func (*Client) Conn ¶
func (c *Client) Conn() ziface.IConnection
func (*Client) GetErrChan ¶
func (*Client) GetLengthField ¶
func (c *Client) GetLengthField() *ziface.LengthField
func (*Client) GetMsgHandler ¶
func (c *Client) GetMsgHandler() ziface.IMsgHandle
func (*Client) GetOnConnStart ¶
func (c *Client) GetOnConnStart() func(ziface.IConnection)
func (*Client) GetOnConnStop ¶
func (c *Client) GetOnConnStop() func(ziface.IConnection)
func (*Client) Restart ¶
func (c *Client) Restart()
Start starts the client, sends requests and establishes a connection. (重新启动客户端,发送请求且建立连接)
func (*Client) SetDecoder ¶
func (*Client) SetOnConnStart ¶
func (c *Client) SetOnConnStart(hookFunc func(ziface.IConnection))
func (*Client) SetOnConnStop ¶
func (c *Client) SetOnConnStop(hookFunc func(ziface.IConnection))
func (*Client) Start ¶
func (c *Client) Start()
Start starts the client, sends requests and establishes a connection. (启动客户端,发送请求且建立链接)
func (*Client) StartHeartBeat ¶
StartHeartBeat starts heartbeat detection with a fixed time interval. interval: the time interval between each heartbeat message. (启动心跳检测, interval: 每次发送心跳的时间间隔)
func (*Client) StartHeartBeatWithOption ¶
func (c *Client) StartHeartBeatWithOption(interval time.Duration, option *ziface.HeartBeatOption)
StartHeartBeatWithOption starts heartbeat detection with a custom callback function. interval: the time interval between each heartbeat message. option: a HeartBeatOption struct that contains the custom callback function and message 启动心跳检测(自定义回调)
type ClientOption ¶
Options for Client
func WithPacketClient ¶
func WithPacketClient(pack ziface.IDataPack) ClientOption
Implement custom data packet format by implementing the Packet interface for client, otherwise use the default data packet format
type ConnManager ¶
type ConnManager struct {
// contains filtered or unexported fields
}
func (*ConnManager) Add ¶
func (connMgr *ConnManager) Add(conn ziface.IConnection)
func (*ConnManager) ClearConn ¶
func (connMgr *ConnManager) ClearConn()
func (*ConnManager) Get ¶
func (connMgr *ConnManager) Get(connID uint64) (ziface.IConnection, error)
func (*ConnManager) Get2 ¶
func (connMgr *ConnManager) Get2(strConnId string) (ziface.IConnection, error)
Get2 It is recommended to use this method to obtain connection instances
func (*ConnManager) GetAllConnID ¶
func (connMgr *ConnManager) GetAllConnID() []uint64
func (*ConnManager) GetAllConnIdStr ¶
func (connMgr *ConnManager) GetAllConnIdStr() []string
func (*ConnManager) Len ¶
func (connMgr *ConnManager) Len() int
func (*ConnManager) Range ¶
func (connMgr *ConnManager) Range(cb func(uint64, ziface.IConnection, interface{}) error, args interface{}) (err error)
func (*ConnManager) Range2 ¶
func (connMgr *ConnManager) Range2(cb func(string, ziface.IConnection, interface{}) error, args interface{}) (err error)
Range2 It is recommended to use this method to 'Range'
func (*ConnManager) Remove ¶
func (connMgr *ConnManager) Remove(conn ziface.IConnection)
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection TCP connection module Used to handle the read and write business of TCP connections, one Connection corresponds to one connection (用于处理Tcp连接的读写业务 一个连接对应一个Connection)
func (*Connection) Context ¶
func (c *Connection) Context() context.Context
func (*Connection) GetConnID ¶
func (c *Connection) GetConnID() uint64
func (*Connection) GetConnIdStr ¶
func (c *Connection) GetConnIdStr() string
func (*Connection) GetConnection ¶
func (c *Connection) GetConnection() net.Conn
func (*Connection) GetMsgHandler ¶
func (c *Connection) GetMsgHandler() ziface.IMsgHandle
func (*Connection) GetName ¶
func (c *Connection) GetName() string
func (*Connection) GetProperty ¶
func (c *Connection) GetProperty(key string) (interface{}, error)
func (*Connection) GetTCPConnection
deprecated
func (c *Connection) GetTCPConnection() net.Conn
Deprecated: use GetConnection instead
func (*Connection) GetWorkerID ¶
func (c *Connection) GetWorkerID() uint32
func (*Connection) GetWsConn ¶
func (c *Connection) GetWsConn() *websocket.Conn
func (*Connection) IsAlive ¶
func (c *Connection) IsAlive() bool
func (*Connection) LocalAddr ¶
func (c *Connection) LocalAddr() net.Addr
func (*Connection) LocalAddrString ¶
func (c *Connection) LocalAddrString() string
func (*Connection) RemoteAddr ¶
func (c *Connection) RemoteAddr() net.Addr
func (*Connection) RemoteAddrString ¶
func (c *Connection) RemoteAddrString() string
func (*Connection) RemoveProperty ¶
func (c *Connection) RemoveProperty(key string)
func (*Connection) Send ¶
func (c *Connection) Send(data []byte) error
func (*Connection) SendBuffMsg ¶
func (c *Connection) SendBuffMsg(msgID uint32, data []byte) error
func (*Connection) SendMsg ¶
func (c *Connection) SendMsg(msgID uint32, data []byte) error
SendMsg directly sends Message data to the remote TCP client. (直接将Message数据发送数据给远程的TCP客户端)
func (*Connection) SendToQueue ¶
func (c *Connection) SendToQueue(data []byte) error
func (*Connection) SetHeartBeat ¶
func (c *Connection) SetHeartBeat(checker ziface.IHeartbeatChecker)
func (*Connection) SetProperty ¶
func (c *Connection) SetProperty(key string, value interface{})
func (*Connection) Start ¶
func (c *Connection) Start()
Start starts the connection and makes the current connection work. (启动连接,让当前连接开始工作)
func (*Connection) StartReader ¶
func (c *Connection) StartReader()
StartReader is a goroutine that reads data from the client (读消息Goroutine,用于从客户端中读取数据)
func (*Connection) StartWriter ¶
func (c *Connection) StartWriter()
StartWriter is the goroutine that writes messages to the client (写消息Goroutine, 用户将数据发送给客户端)
func (*Connection) Stop ¶
func (c *Connection) Stop()
Stop stops the connection and ends the current connection state. (停止连接,结束当前连接状态)
type GroupRouter ¶
type GroupRouter struct { Handlers []ziface.RouterHandler // contains filtered or unexported fields }
func NewGroup ¶
func NewGroup(start, end uint32, router *RouterSlices, Handlers ...ziface.RouterHandler) *GroupRouter
func (*GroupRouter) AddHandler ¶
func (g *GroupRouter) AddHandler(MsgId uint32, Handlers ...ziface.RouterHandler)
func (*GroupRouter) Use ¶
func (g *GroupRouter) Use(Handlers ...ziface.RouterHandler)
type HeartbeatChecker ¶
type HeartbeatChecker struct {
// contains filtered or unexported fields
}
func (*HeartbeatChecker) BindConn ¶
func (h *HeartbeatChecker) BindConn(conn ziface.IConnection)
func (*HeartbeatChecker) BindRouter ¶
func (h *HeartbeatChecker) BindRouter(msgID uint32, router ziface.IRouter)
func (*HeartbeatChecker) BindRouterSlices ¶
func (h *HeartbeatChecker) BindRouterSlices(msgID uint32, handlers ...ziface.RouterHandler)
func (*HeartbeatChecker) Clone ¶
func (h *HeartbeatChecker) Clone() ziface.IHeartbeatChecker
Clone clones to a specified connection (克隆到一个指定的链接上)
func (*HeartbeatChecker) MsgID ¶
func (h *HeartbeatChecker) MsgID() uint32
func (*HeartbeatChecker) Router ¶
func (h *HeartbeatChecker) Router() ziface.IRouter
func (*HeartbeatChecker) RouterSlices ¶
func (h *HeartbeatChecker) RouterSlices() []ziface.RouterHandler
func (*HeartbeatChecker) SendHeartBeatMsg ¶
func (h *HeartbeatChecker) SendHeartBeatMsg() error
func (*HeartbeatChecker) SetHeartbeatFunc ¶
func (h *HeartbeatChecker) SetHeartbeatFunc(beatFunc ziface.HeartBeatFunc)
func (*HeartbeatChecker) SetHeartbeatMsgFunc ¶
func (h *HeartbeatChecker) SetHeartbeatMsgFunc(f ziface.HeartBeatMsgFunc)
func (*HeartbeatChecker) SetOnRemoteNotAlive ¶
func (h *HeartbeatChecker) SetOnRemoteNotAlive(f ziface.OnRemoteNotAlive)
func (*HeartbeatChecker) Start ¶
func (h *HeartbeatChecker) Start()
func (*HeartbeatChecker) Stop ¶
func (h *HeartbeatChecker) Stop()
type HeatBeatDefaultRouter ¶
type HeatBeatDefaultRouter struct {
BaseRouter
}
Default callback routing business for receiving remote heartbeat messages (收到remote心跳消息的默认回调路由业务)
func (*HeatBeatDefaultRouter) Handle ¶
func (r *HeatBeatDefaultRouter) Handle(req ziface.IRequest)
type KcpConnection ¶
type KcpConnection struct {
// contains filtered or unexported fields
}
Connection KCP connection module Used to handle the read and write business of KCP connections, one Connection corresponds to one connection (用于处理KCP连接的读写业务 一个连接对应一个Connection)
func (*KcpConnection) Context ¶
func (c *KcpConnection) Context() context.Context
func (*KcpConnection) GetConnID ¶
func (c *KcpConnection) GetConnID() uint64
func (*KcpConnection) GetConnIdStr ¶
func (c *KcpConnection) GetConnIdStr() string
func (*KcpConnection) GetConnection ¶
func (c *KcpConnection) GetConnection() net.Conn
func (*KcpConnection) GetMsgHandler ¶
func (c *KcpConnection) GetMsgHandler() ziface.IMsgHandle
func (*KcpConnection) GetName ¶
func (c *KcpConnection) GetName() string
func (*KcpConnection) GetProperty ¶
func (c *KcpConnection) GetProperty(key string) (interface{}, error)
func (*KcpConnection) GetTCPConnection
deprecated
func (c *KcpConnection) GetTCPConnection() net.Conn
Deprecated: use GetConnection instead
func (*KcpConnection) GetWorkerID ¶
func (c *KcpConnection) GetWorkerID() uint32
func (*KcpConnection) GetWsConn ¶
func (c *KcpConnection) GetWsConn() *websocket.Conn
func (*KcpConnection) IsAlive ¶
func (c *KcpConnection) IsAlive() bool
func (*KcpConnection) LocalAddr ¶
func (c *KcpConnection) LocalAddr() net.Addr
func (*KcpConnection) LocalAddrString ¶
func (c *KcpConnection) LocalAddrString() string
func (*KcpConnection) RemoteAddr ¶
func (c *KcpConnection) RemoteAddr() net.Addr
func (*KcpConnection) RemoteAddrString ¶
func (c *KcpConnection) RemoteAddrString() string
func (*KcpConnection) RemoveProperty ¶
func (c *KcpConnection) RemoveProperty(key string)
func (*KcpConnection) Send ¶
func (c *KcpConnection) Send(data []byte) error
func (*KcpConnection) SendBuffMsg ¶
func (c *KcpConnection) SendBuffMsg(msgID uint32, data []byte) error
func (*KcpConnection) SendMsg ¶
func (c *KcpConnection) SendMsg(msgID uint32, data []byte) error
SendMsg directly sends Message data to the remote KCP client. (直接将Message数据发送数据给远程的KCP客户端)
func (*KcpConnection) SendToQueue ¶
func (c *KcpConnection) SendToQueue(data []byte) error
func (*KcpConnection) SetHeartBeat ¶
func (c *KcpConnection) SetHeartBeat(checker ziface.IHeartbeatChecker)
func (*KcpConnection) SetProperty ¶
func (c *KcpConnection) SetProperty(key string, value interface{})
func (*KcpConnection) Start ¶
func (c *KcpConnection) Start()
Start starts the connection and makes the current connection work. (启动连接,让当前连接开始工作)
func (*KcpConnection) StartReader ¶
func (c *KcpConnection) StartReader()
StartReader is a goroutine that reads data from the client (读消息Goroutine,用于从客户端中读取数据)
func (*KcpConnection) StartWriter ¶
func (c *KcpConnection) StartWriter()
StartWriter is the goroutine that writes messages to the client (写消息Goroutine, 用户将数据发送给客户端)
func (*KcpConnection) Stop ¶
func (c *KcpConnection) Stop()
Stop stops the connection and ends the current connection state. (停止连接,结束当前连接状态)
type MsgHandle ¶
type MsgHandle struct { // A map property that stores the processing methods for each MsgID // (存放每个MsgID 所对应的处理方法的map属性) Apis map[uint32]ziface.IRouter // The number of worker goroutines in the business work Worker pool // (业务工作Worker池的数量) WorkerPoolSize uint32 // A message queue for workers to take tasks // (Worker负责取任务的消息队列) TaskQueue []chan ziface.IRequest RouterSlices *RouterSlices // contains filtered or unexported fields }
MsgHandle is the module for handling message processing callbacks (对消息的处理回调模块)
func (*MsgHandle) AddInterceptor ¶
func (mh *MsgHandle) AddInterceptor(interceptor ziface.IInterceptor)
func (*MsgHandle) AddRouterSlices ¶
func (mh *MsgHandle) AddRouterSlices(msgId uint32, handler ...ziface.RouterHandler) ziface.IRouterSlices
AddRouterSlices adds router handlers using slices (切片路由添加)
func (*MsgHandle) Group ¶
func (mh *MsgHandle) Group(start, end uint32, Handlers ...ziface.RouterHandler) ziface.IGroupRouterSlices
Group routes into a group (路由分组)
func (*MsgHandle) Intercept ¶
Data processing interceptor that is necessary by default in Zinx (Zinx默认必经的数据处理拦截器)
func (*MsgHandle) SendMsgToTaskQueue ¶
SendMsgToTaskQueue sends the message to the TaskQueue for processing by the worker (将消息交给TaskQueue,由worker进行处理)
func (*MsgHandle) StartOneWorker ¶
StartOneWorker starts a worker workflow (启动一个Worker工作流程)
func (*MsgHandle) StartWorkerPool ¶
func (mh *MsgHandle) StartWorkerPool()
StartWorkerPool starts the worker pool
func (*MsgHandle) Use ¶
func (mh *MsgHandle) Use(Handlers ...ziface.RouterHandler) ziface.IRouterSlices
type Option ¶
type Option func(s *Server)
Options for Server (Server的服务Option)
func WithPacket ¶
Implement custom data packet format by implementing the Packet interface, otherwise use the default data packet format (只要实现Packet 接口可自由实现数据包解析格式,如果没有则使用默认解析格式)
type Request ¶
type Request struct { ziface.BaseRequest // contains filtered or unexported fields }
Request 请求
func (*Request) BindRouter ¶
func (*Request) BindRouterSlices ¶
func (r *Request) BindRouterSlices(handlers []ziface.RouterHandler)
New version
func (*Request) GetConnection ¶
func (r *Request) GetConnection() ziface.IConnection
func (*Request) GetMessage ¶
func (*Request) GetResponse ¶
func (*Request) Goto ¶
func (r *Request) Goto(step ziface.HandleStep)
func (*Request) RouterSlicesNext ¶
func (r *Request) RouterSlicesNext()
func (*Request) SetResponse ¶
type RequestFunc ¶
type RequestFunc struct { ziface.BaseRequest // contains filtered or unexported fields }
func (*RequestFunc) CallFunc ¶
func (rf *RequestFunc) CallFunc()
func (*RequestFunc) GetConnection ¶
func (rf *RequestFunc) GetConnection() ziface.IConnection
type RouterSlices ¶
type RouterSlices struct { Apis map[uint32][]ziface.RouterHandler Handlers []ziface.RouterHandler sync.RWMutex }
func NewRouterSlices ¶
func NewRouterSlices() *RouterSlices
func (*RouterSlices) AddHandler ¶
func (r *RouterSlices) AddHandler(msgId uint32, Handlers ...ziface.RouterHandler)
func (*RouterSlices) GetHandlers ¶
func (r *RouterSlices) GetHandlers(MsgId uint32) ([]ziface.RouterHandler, bool)
func (*RouterSlices) Group ¶
func (r *RouterSlices) Group(start, end uint32, Handlers ...ziface.RouterHandler) ziface.IGroupRouterSlices
func (*RouterSlices) Use ¶
func (r *RouterSlices) Use(handles ...ziface.RouterHandler)
type Server ¶
type Server struct { // Name of the server (服务器的名称) Name string //tcp4 or other IPVersion string // IP version (e.g. "tcp4") - 服务绑定的IP地址 IP string // IP address the server is bound to (服务绑定的端口) Port int // 服务绑定的websocket 端口 (Websocket port the server is bound to) WsPort int // 服务绑定的kcp 端口 (kcp port the server is bound to) KcpPort int // 服务绑定的udp 端口 (udp port the server is bound to) UdpPort int // Routing mode (路由模式) RouterSlicesMode bool // Current server's connection manager (当前Server的链接管理器) ConnMgr ziface.IConnManager // contains filtered or unexported fields }
Server interface implementation, defines a Server service class (接口实现,定义一个Server服务类)
func (*Server) AddInterceptor ¶
func (s *Server) AddInterceptor(interceptor ziface.IInterceptor)
func (*Server) AddRouterSlices ¶
func (s *Server) AddRouterSlices(msgID uint32, router ...ziface.RouterHandler) ziface.IRouterSlices
func (*Server) GetConnMgr ¶
func (s *Server) GetConnMgr() ziface.IConnManager
func (*Server) GetHeartBeat ¶
func (s *Server) GetHeartBeat() ziface.IHeartbeatChecker
func (*Server) GetLengthField ¶
func (s *Server) GetLengthField() *ziface.LengthField
func (*Server) GetMsgHandler ¶
func (s *Server) GetMsgHandler() ziface.IMsgHandle
func (*Server) GetOnConnStart ¶
func (s *Server) GetOnConnStart() func(ziface.IConnection)
func (*Server) GetOnConnStop ¶
func (s *Server) GetOnConnStop() func(ziface.IConnection)
func (*Server) Group ¶
func (s *Server) Group(start, end uint32, Handlers ...ziface.RouterHandler) ziface.IGroupRouterSlices
func (*Server) ListenKcpConn ¶
func (s *Server) ListenKcpConn()
func (*Server) ListenTcpConn ¶
func (s *Server) ListenTcpConn()
func (*Server) ListenUDPConn ¶
func (s *Server) ListenUDPConn()
func (*Server) ListenWebsocketConn ¶
func (s *Server) ListenWebsocketConn()
func (*Server) ServerName ¶
func (*Server) SetDecoder ¶
func (*Server) SetOnConnStart ¶
func (s *Server) SetOnConnStart(hookFunc func(ziface.IConnection))
func (*Server) SetOnConnStop ¶
func (s *Server) SetOnConnStop(hookFunc func(ziface.IConnection))
func (*Server) StartConn ¶
func (s *Server) StartConn(conn ziface.IConnection)
func (*Server) StartHeartBeat ¶
StartHeartBeat starts the heartbeat check. interval is the time interval between each heartbeat. (启动心跳检测 interval 每次发送心跳的时间间隔)
func (*Server) StartHeartBeatWithOption ¶
func (s *Server) StartHeartBeatWithOption(interval time.Duration, option *ziface.HeartBeatOption)
StartHeartBeatWithOption starts the heartbeat detection with the given configuration. interval is the time interval for sending heartbeat messages. option is the configuration for heartbeat detection. 启动心跳检测 (option 心跳检测的配置)
func (*Server) Use ¶
func (s *Server) Use(Handlers ...ziface.RouterHandler) ziface.IRouterSlices
type WsConnection ¶
type WsConnection struct {
// contains filtered or unexported fields
}
WsConnection is a module for handling the read and write operations of a WebSocket connection. (Websocket连接模块, 用于处理 Websocket 连接的读写业务 一个连接对应一个Connection)
func (*WsConnection) Context ¶
func (c *WsConnection) Context() context.Context
Context returns the context for the connection, which can be used by user-defined goroutines to get the connection exit status. (返回ctx,用于用户自定义的go程获取连接退出状态)
func (*WsConnection) GetConnID ¶
func (c *WsConnection) GetConnID() uint64
func (*WsConnection) GetConnIdStr ¶
func (c *WsConnection) GetConnIdStr() string
func (*WsConnection) GetConnection ¶
func (c *WsConnection) GetConnection() net.Conn
func (*WsConnection) GetMsgHandler ¶
func (c *WsConnection) GetMsgHandler() ziface.IMsgHandle
func (*WsConnection) GetName ¶
func (c *WsConnection) GetName() string
func (*WsConnection) GetProperty ¶
func (c *WsConnection) GetProperty(key string) (interface{}, error)
func (*WsConnection) GetTCPConnection
deprecated
func (c *WsConnection) GetTCPConnection() net.Conn
Deprecated: use GetConnection instead
func (*WsConnection) GetWorkerID ¶
func (c *WsConnection) GetWorkerID() uint32
func (*WsConnection) GetWsConn ¶
func (c *WsConnection) GetWsConn() *websocket.Conn
func (*WsConnection) IsAlive ¶
func (c *WsConnection) IsAlive() bool
func (*WsConnection) LocalAddr ¶
func (c *WsConnection) LocalAddr() net.Addr
func (*WsConnection) LocalAddrString ¶
func (c *WsConnection) LocalAddrString() string
func (*WsConnection) RemoteAddr ¶
func (c *WsConnection) RemoteAddr() net.Addr
func (*WsConnection) RemoteAddrString ¶
func (c *WsConnection) RemoteAddrString() string
func (*WsConnection) RemoveProperty ¶
func (c *WsConnection) RemoveProperty(key string)
func (*WsConnection) Send ¶
func (c *WsConnection) Send(data []byte) error
func (*WsConnection) SendBuffMsg ¶
func (c *WsConnection) SendBuffMsg(msgID uint32, data []byte) error
SendBuffMsg sends BuffMsg
func (*WsConnection) SendMsg ¶
func (c *WsConnection) SendMsg(msgID uint32, data []byte) error
SendMsg directly sends the Message data to the remote TCP client. (直接将Message数据发送数据给远程的TCP客户端)性能低
func (*WsConnection) SendToQueue ¶
func (c *WsConnection) SendToQueue(data []byte) error
func (*WsConnection) SetHeartBeat ¶
func (c *WsConnection) SetHeartBeat(checker ziface.IHeartbeatChecker)
func (*WsConnection) SetProperty ¶
func (c *WsConnection) SetProperty(key string, value interface{})
func (*WsConnection) Start ¶
func (c *WsConnection) Start()
Start starts the connection and makes it work. (Start 启动连接,让当前连接开始工作)
func (*WsConnection) StartReader ¶
func (c *WsConnection) StartReader()
StartReader is a Goroutine that reads messages from the client. (StartReader 读消息Goroutine,用于从客户端中读取数据)
func (*WsConnection) StartWriter ¶
func (c *WsConnection) StartWriter()
StartWriter is a Goroutine that sends messages to the client (StartWriter 写消息Goroutine, 用户将数据发送给客户端)
func (*WsConnection) Stop ¶
func (c *WsConnection) Stop()
Stop stops the connection and ends its current state. (停止连接,结束当前连接状态)