Documentation ¶
Index ¶
- Constants
- Variables
- func HeatBeatDefaultHandle(req iface.IRequest)
- func NewClient(ip string, port int, opts ...ClientOption) iface.IClient
- func NewDefaultRouterSlicesServer(opts ...Option) iface.IServer
- func NewFuncRequest(conn iface.IConnection, callFunc func()) iface.IRequest
- func NewHeartbeatChecker(interval time.Duration) iface.IHeartbeatChecker
- func NewRequest(conn iface.IConnection, msg iface.IMessage) iface.IRequest
- func NewServer(opts ...Option) iface.IServer
- func NewTLSClient(ip string, port int, opts ...ClientOption) iface.IClient
- func NewUserConfDefaultRouterSlicesServer(config *conf.Config, opts ...Option) iface.IServer
- func NewUserConfServer(config *conf.Config, opts ...Option) iface.IServer
- func NewWsClient(ip string, port int, opts ...ClientOption) iface.IClient
- func RouterRecovery(request iface.IRequest)
- func RouterTime(request iface.IRequest)
- type BaseRouter
- type Client
- func (c *Client) AddInterceptor(interceptor iface.IInterceptor)
- func (c *Client) AddRouter(msgID uint32, router iface.IRouter)
- func (c *Client) Conn() iface.IConnection
- func (c *Client) GetErrChan() chan error
- func (c *Client) GetLengthField() *iface.LengthField
- func (c *Client) GetMsgHandler() iface.IMsgHandle
- func (c *Client) GetName() string
- func (c *Client) GetOnConnStart() func(iface.IConnection)
- func (c *Client) GetOnConnStop() func(iface.IConnection)
- func (c *Client) GetPacket() iface.IDataPack
- func (c *Client) Restart()
- func (c *Client) SetDecoder(decoder iface.IDecoder)
- func (c *Client) SetName(name string)
- func (c *Client) SetOnConnStart(hookFunc func(iface.IConnection))
- func (c *Client) SetOnConnStop(hookFunc func(iface.IConnection))
- func (c *Client) SetPacket(packet iface.IDataPack)
- func (c *Client) Start()
- func (c *Client) StartHeartBeat(interval time.Duration)
- func (c *Client) StartHeartBeatWithOption(interval time.Duration, option *iface.HeartBeatOption)
- func (c *Client) Stop()
- type ClientOption
- type ConnManager
- func (connMgr *ConnManager) Add(conn iface.IConnection)
- func (connMgr *ConnManager) ClearConn()
- func (connMgr *ConnManager) Get(connID uint64) (iface.IConnection, error)
- func (connMgr *ConnManager) GetAllConnID() []uint64
- func (connMgr *ConnManager) Len() int
- func (connMgr *ConnManager) Range(cb func(uint64, iface.IConnection, interface{}) error, args interface{}) (err error)
- func (connMgr *ConnManager) Remove(conn iface.IConnection)
- type Connection
- func (c *Connection) Context() context.Context
- func (c *Connection) GetConnID() uint64
- func (c *Connection) GetConnection() net.Conn
- func (c *Connection) GetMsgHandler() iface.IMsgHandle
- func (c *Connection) GetName() string
- func (c *Connection) GetProperty(key string) (interface{}, error)
- func (c *Connection) GetTCPConnection() net.Conndeprecated
- 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 iface.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 iface.IConnection)
- func (h *HeartbeatChecker) BindRouter(msgID uint32, router iface.IRouter)
- func (h *HeartbeatChecker) BindRouterSlices(msgID uint32, handlers ...iface.RouterHandler)
- func (h *HeartbeatChecker) Clone() iface.IHeartbeatChecker
- func (h *HeartbeatChecker) MsgID() uint32
- func (h *HeartbeatChecker) Router() iface.IRouter
- func (h *HeartbeatChecker) RouterSlices() []iface.RouterHandler
- func (h *HeartbeatChecker) SendHeartBeatMsg() error
- func (h *HeartbeatChecker) SetHeartbeatFunc(beatFunc iface.HeartBeatFunc)
- func (h *HeartbeatChecker) SetHeartbeatMsgFunc(f iface.HeartBeatMsgFunc)
- func (h *HeartbeatChecker) SetOnRemoteNotAlive(f iface.OnRemoteNotAlive)
- func (h *HeartbeatChecker) Start()
- func (h *HeartbeatChecker) Stop()
- type HeatBeatDefaultRouter
- type MsgHandle
- func (mh *MsgHandle) AddInterceptor(interceptor iface.IInterceptor)
- func (mh *MsgHandle) AddRouter(msgID uint32, router iface.IRouter)
- func (mh *MsgHandle) AddRouterSlices(msgId uint32, handler ...iface.RouterHandler) iface.IRouterSlices
- func (mh *MsgHandle) Execute(request iface.IRequest)
- func (mh *MsgHandle) GetTaskQueueWorkerId(request iface.IRequest) uint64
- func (mh *MsgHandle) Group(start, end uint32, Handlers ...iface.RouterHandler) iface.IGroupRouterSlices
- func (mh *MsgHandle) Intercept(chain iface.IChain) iface.IcResp
- func (mh *MsgHandle) SendMsgToTaskQueue(request iface.IRequest)
- func (mh *MsgHandle) StartOneWorker(workerID int, taskQueue chan iface.IRequest)
- func (mh *MsgHandle) StartWorkerPool()
- func (mh *MsgHandle) Use(Handlers ...iface.RouterHandler) iface.IRouterSlices
- type Option
- type Request
- func (r *Request) Abort()
- func (r *Request) BindRouter(router iface.IRouter)
- func (r *Request) BindRouterSlices(handlers []iface.RouterHandler)
- func (r *Request) Call()
- func (r *Request) GetConnection() iface.IConnection
- func (r *Request) GetData() []byte
- func (r *Request) GetMessage() iface.IMessage
- func (r *Request) GetMsgID() uint32
- func (r *Request) GetResponse() iface.IcResp
- func (r *Request) Goto(step iface.HandleStep)
- func (r *Request) RouterSlicesNext()
- func (r *Request) SetResponse(response iface.IcResp)
- type RequestFunc
- type RouterSlices
- func (r *RouterSlices) AddHandler(msgId uint32, Handlers ...iface.RouterHandler)
- func (r *RouterSlices) GetHandlers(MsgId uint32) ([]iface.RouterHandler, bool)
- func (r *RouterSlices) Group(start, end uint32, Handlers ...iface.RouterHandler) iface.IGroupRouterSlices
- func (r *RouterSlices) Use(handles ...iface.RouterHandler)
- type Server
- func (s *Server) AddInterceptor(interceptor iface.IInterceptor)
- func (s *Server) AddRouter(msgID uint32, router iface.IRouter)
- func (s *Server) AddRouterSlices(msgID uint32, router ...iface.RouterHandler) iface.IRouterSlices
- func (s *Server) GetConnMgr() iface.IConnManager
- func (s *Server) GetHeartBeat() iface.IHeartbeatChecker
- func (s *Server) GetLengthField() *iface.LengthField
- func (s *Server) GetMsgHandler() iface.IMsgHandle
- func (s *Server) GetOnConnStart() func(iface.IConnection)
- func (s *Server) GetOnConnStop() func(iface.IConnection)
- func (s *Server) GetPacket() iface.IDataPack
- func (s *Server) Group(start, end uint32, Handlers ...iface.RouterHandler) iface.IGroupRouterSlices
- func (s *Server) ListenTcpConn() error
- func (s *Server) ListenWebsocketConn() error
- func (s *Server) Serve()
- func (s *Server) ServerName() string
- func (s *Server) SetDecoder(decoder iface.IDecoder)
- func (s *Server) SetOnConnStart(hookFunc func(iface.IConnection))
- func (s *Server) SetOnConnStop(hookFunc func(iface.IConnection))
- func (s *Server) SetPacket(packet iface.IDataPack)
- func (s *Server) SetWebsocketAuth(f func(r *http.Request) error)
- func (s *Server) Start(_ context.Context) error
- func (s *Server) StartConn(conn iface.IConnection)
- func (s *Server) StartHeartBeat(interval time.Duration)
- func (s *Server) StartHeartBeatWithOption(interval time.Duration, option *iface.HeartBeatOption)
- func (s *Server) Stop(ctx context.Context) error
- func (s *Server) Use(Handlers ...iface.RouterHandler) iface.IRouterSlices
- type WsConnection
- func (c *WsConnection) Context() context.Context
- func (c *WsConnection) GetConnID() uint64
- func (c *WsConnection) GetConnection() net.Conn
- func (c *WsConnection) GetMsgHandler() iface.IMsgHandle
- func (c *WsConnection) GetName() string
- func (c *WsConnection) GetProperty(key string) (interface{}, error)
- func (c *WsConnection) GetTCPConnection() net.Conndeprecated
- 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 iface.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 iface.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 iface.IConnection, callFunc func()) iface.IRequest
func NewHeartbeatChecker ¶
func NewHeartbeatChecker(interval time.Duration) iface.IHeartbeatChecker
func NewRequest ¶
func NewTLSClient ¶
func NewTLSClient(ip string, port int, opts ...ClientOption) iface.IClient
func NewUserConfDefaultRouterSlicesServer ¶
NewUserRouterSlicesServer 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) iface.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 iface.IInterceptor)
func (*Client) Conn ¶
func (c *Client) Conn() iface.IConnection
func (*Client) GetErrChan ¶
func (*Client) GetLengthField ¶
func (c *Client) GetLengthField() *iface.LengthField
func (*Client) GetMsgHandler ¶
func (c *Client) GetMsgHandler() iface.IMsgHandle
func (*Client) GetOnConnStart ¶
func (c *Client) GetOnConnStart() func(iface.IConnection)
func (*Client) GetOnConnStop ¶
func (c *Client) GetOnConnStop() func(iface.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(iface.IConnection))
func (*Client) SetOnConnStop ¶
func (c *Client) SetOnConnStop(hookFunc func(iface.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 *iface.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 iface.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 iface.IConnection)
func (*ConnManager) ClearConn ¶
func (connMgr *ConnManager) ClearConn()
func (*ConnManager) Get ¶
func (connMgr *ConnManager) Get(connID uint64) (iface.IConnection, error)
func (*ConnManager) GetAllConnID ¶
func (connMgr *ConnManager) GetAllConnID() []uint64
func (*ConnManager) Len ¶
func (connMgr *ConnManager) Len() int
func (*ConnManager) Range ¶
func (connMgr *ConnManager) Range(cb func(uint64, iface.IConnection, interface{}) error, args interface{}) (err error)
func (*ConnManager) Remove ¶
func (connMgr *ConnManager) Remove(conn iface.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) GetConnection ¶
func (c *Connection) GetConnection() net.Conn
func (*Connection) GetMsgHandler ¶
func (c *Connection) GetMsgHandler() iface.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) 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 iface.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 []iface.RouterHandler // contains filtered or unexported fields }
func NewGroup ¶
func NewGroup(start, end uint32, router *RouterSlices, Handlers ...iface.RouterHandler) *GroupRouter
func (*GroupRouter) AddHandler ¶
func (g *GroupRouter) AddHandler(MsgId uint32, Handlers ...iface.RouterHandler)
func (*GroupRouter) Use ¶
func (g *GroupRouter) Use(Handlers ...iface.RouterHandler)
type HeartbeatChecker ¶
type HeartbeatChecker struct {
// contains filtered or unexported fields
}
func (*HeartbeatChecker) BindConn ¶
func (h *HeartbeatChecker) BindConn(conn iface.IConnection)
func (*HeartbeatChecker) BindRouter ¶
func (h *HeartbeatChecker) BindRouter(msgID uint32, router iface.IRouter)
func (*HeartbeatChecker) BindRouterSlices ¶
func (h *HeartbeatChecker) BindRouterSlices(msgID uint32, handlers ...iface.RouterHandler)
func (*HeartbeatChecker) Clone ¶
func (h *HeartbeatChecker) Clone() iface.IHeartbeatChecker
Clone clones to a specified connection (克隆到一个指定的链接上)
func (*HeartbeatChecker) MsgID ¶
func (h *HeartbeatChecker) MsgID() uint32
func (*HeartbeatChecker) Router ¶
func (h *HeartbeatChecker) Router() iface.IRouter
func (*HeartbeatChecker) RouterSlices ¶
func (h *HeartbeatChecker) RouterSlices() []iface.RouterHandler
func (*HeartbeatChecker) SendHeartBeatMsg ¶
func (h *HeartbeatChecker) SendHeartBeatMsg() error
func (*HeartbeatChecker) SetHeartbeatFunc ¶
func (h *HeartbeatChecker) SetHeartbeatFunc(beatFunc iface.HeartBeatFunc)
func (*HeartbeatChecker) SetHeartbeatMsgFunc ¶
func (h *HeartbeatChecker) SetHeartbeatMsgFunc(f iface.HeartBeatMsgFunc)
func (*HeartbeatChecker) SetOnRemoteNotAlive ¶
func (h *HeartbeatChecker) SetOnRemoteNotAlive(f iface.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 iface.IRequest)
type MsgHandle ¶
type MsgHandle struct { // A map property that stores the processing methods for each MsgID // (存放每个MsgID 所对应的处理方法的map属性) Apis map[uint32]iface.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 iface.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 iface.IInterceptor)
func (*MsgHandle) AddRouterSlices ¶
func (mh *MsgHandle) AddRouterSlices(msgId uint32, handler ...iface.RouterHandler) iface.IRouterSlices
AddRouterSlices adds router handlers using slices (切片路由添加)
func (*MsgHandle) GetTaskQueueWorkerId ¶
func (*MsgHandle) Group ¶
func (mh *MsgHandle) Group(start, end uint32, Handlers ...iface.RouterHandler) iface.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 ...iface.RouterHandler) iface.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 { iface.BaseRequest // contains filtered or unexported fields }
Request 请求
func (*Request) BindRouter ¶
func (*Request) BindRouterSlices ¶
func (r *Request) BindRouterSlices(handlers []iface.RouterHandler)
New version
func (*Request) GetConnection ¶
func (r *Request) GetConnection() iface.IConnection
func (*Request) GetMessage ¶
func (*Request) GetResponse ¶
func (*Request) Goto ¶
func (r *Request) Goto(step iface.HandleStep)
func (*Request) RouterSlicesNext ¶
func (r *Request) RouterSlicesNext()
func (*Request) SetResponse ¶
type RequestFunc ¶
type RequestFunc struct { iface.BaseRequest // contains filtered or unexported fields }
func (*RequestFunc) CallFunc ¶
func (rf *RequestFunc) CallFunc()
func (*RequestFunc) GetConnection ¶
func (rf *RequestFunc) GetConnection() iface.IConnection
type RouterSlices ¶
type RouterSlices struct { Apis map[uint32][]iface.RouterHandler Handlers []iface.RouterHandler sync.RWMutex }
func NewRouterSlices ¶
func NewRouterSlices() *RouterSlices
func (*RouterSlices) AddHandler ¶
func (r *RouterSlices) AddHandler(msgId uint32, Handlers ...iface.RouterHandler)
func (*RouterSlices) GetHandlers ¶
func (r *RouterSlices) GetHandlers(MsgId uint32) ([]iface.RouterHandler, bool)
func (*RouterSlices) Group ¶
func (r *RouterSlices) Group(start, end uint32, Handlers ...iface.RouterHandler) iface.IGroupRouterSlices
func (*RouterSlices) Use ¶
func (r *RouterSlices) Use(handles ...iface.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 // Routing mode (路由模式) RouterSlicesMode bool // Current server's connection manager (当前Server的链接管理器) ConnMgr iface.IConnManager // contains filtered or unexported fields }
Server interface implementation, defines a Server service class (接口实现,定义一个Server服务类)
func (*Server) AddInterceptor ¶
func (s *Server) AddInterceptor(interceptor iface.IInterceptor)
func (*Server) AddRouterSlices ¶
func (s *Server) AddRouterSlices(msgID uint32, router ...iface.RouterHandler) iface.IRouterSlices
func (*Server) GetConnMgr ¶
func (s *Server) GetConnMgr() iface.IConnManager
func (*Server) GetHeartBeat ¶
func (s *Server) GetHeartBeat() iface.IHeartbeatChecker
func (*Server) GetLengthField ¶
func (s *Server) GetLengthField() *iface.LengthField
func (*Server) GetMsgHandler ¶
func (s *Server) GetMsgHandler() iface.IMsgHandle
func (*Server) GetOnConnStart ¶
func (s *Server) GetOnConnStart() func(iface.IConnection)
func (*Server) GetOnConnStop ¶
func (s *Server) GetOnConnStop() func(iface.IConnection)
func (*Server) Group ¶
func (s *Server) Group(start, end uint32, Handlers ...iface.RouterHandler) iface.IGroupRouterSlices
func (*Server) ListenTcpConn ¶
func (*Server) ListenWebsocketConn ¶
func (*Server) ServerName ¶
func (*Server) SetDecoder ¶
func (*Server) SetOnConnStart ¶
func (s *Server) SetOnConnStart(hookFunc func(iface.IConnection))
func (*Server) SetOnConnStop ¶
func (s *Server) SetOnConnStop(hookFunc func(iface.IConnection))
func (*Server) StartConn ¶
func (s *Server) StartConn(conn iface.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 *iface.HeartBeatOption)
StartHeartBeatWithFunc 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 ...iface.RouterHandler) iface.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) GetConnection ¶
func (c *WsConnection) GetConnection() net.Conn
func (*WsConnection) GetMsgHandler ¶
func (c *WsConnection) GetMsgHandler() iface.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) 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 iface.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. (停止连接,结束当前连接状态)