Documentation ¶
Index ¶
- Variables
- func GetDeviceID(sid int64) (datacenterid, workerid int64)
- func GetGenTime(sid int64) (t string)
- func GetGenTimestamp(sid int64) (timestamp int64)
- func GetTimestamp(sid int64) (timestamp int64)
- func GetTimestampStatus() (state float64)
- func NewServer() ziface.IServer
- type BaseRouter
- type ConnManager
- type Connection
- func (c *Connection) DelJoinRoomById(room string)
- func (c *Connection) GetConnID() int64
- func (c *Connection) GetJoinRooms() map[string]bool
- func (c *Connection) GetMessageType() int
- func (c *Connection) GetProperty(key string) (p interface{}, err error)
- func (c *Connection) GetSnowflakeID() int64
- func (c *Connection) GetWsConnection() *zsocket.Conn
- func (c *Connection) HeartbeatChecker()
- func (c *Connection) IsAlive() bool
- func (c *Connection) IsClosed() bool
- func (c *Connection) IsJoinRoom(room string) bool
- func (c *Connection) KeepAlive()
- func (c *Connection) RemoteAddr() net.Addr
- func (c *Connection) RemoveProperty(key string)
- func (c *Connection) SendBuffByteMsg(data []byte)
- func (c *Connection) SendBuffMsg(data string)
- func (c *Connection) SendByteMsg(data string)
- func (c *Connection) SendErrorMsg(error string)
- func (c *Connection) SendMsg(data string)
- func (c *Connection) SetJoinRooms(room string)
- func (c *Connection) SetMessageType(mt int)
- 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 Error
- type Limiter
- func (l *Limiter) Accept(conn net.Conn) (func(), error)
- func (l *Limiter) Config() LimiterConfig
- func (l *Limiter) HTTPConnStateFunc() func(net.Conn, http.ConnState)
- func (l *Limiter) HTTPConnStateFuncWithErrorHandler(errorHandler func(error, net.Conn)) func(net.Conn, http.ConnState)
- func (l *Limiter) NumOpen(addr net.Addr) int
- func (l *Limiter) SetConfig(c LimiterConfig)
- type LimiterConfig
- type Message
- type MsgHandle
- func (mh *MsgHandle) DoMsgHandler(request ziface.IRequest)
- func (mh *MsgHandle) SendMsgToTaskQueue(request ziface.IRequest)
- func (mh *MsgHandle) SetRouter(command string, ctype string, name string, router ziface.IRouter)
- func (mh *MsgHandle) StartOneWorker(workerID int, taskQueue chan ziface.IRequest)
- func (mh *MsgHandle) StartWorkerPool()
- type Request
- type Router
- type Server
- func (s *Server) CallOnConnStart(conn ziface.IConnection)
- func (s *Server) CallOnConnStop(conn ziface.IConnection)
- func (s *Server) CallOnMaxConn(conn *zsocket.Conn)
- func (s *Server) GetConnMgr() ziface.IConnManager
- func (s *Server) GetSnowflakeMgr() ziface.ISnowflake
- func (s *Server) Serve()
- func (s *Server) SetOnConnStart(hookStart func(conn ziface.IConnection))
- func (s *Server) SetOnConnStop(hookStop func(conn ziface.IConnection))
- func (s *Server) SetOnMaxConn(hookConn func(conn *zsocket.Conn))
- func (s *Server) SetRouter(command string, ctype string, name string, router ziface.IRouter)
- func (s *Server) Start()
- func (s *Server) Stop()
- type Snowflake
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrPerClientIPLimitReached = errors.New("client connection limit reached")
)
Functions ¶
Types ¶
type ConnManager ¶
type ConnManager struct {
// contains filtered or unexported fields
}
连接管理
func (*ConnManager) Get ¶
func (connMgr *ConnManager) Get(connID int64) (ziface.IConnection, error)
根据id查找连接
type Connection ¶
type Connection struct { //心跳检查间隔 HeartbeatInterval int // 加入了哪些房间 Rooms map[string]bool //当前属于那个server WsServer ziface.IServer //当前连接的ws Conn *zsocket.Conn //连接id ConnID int64 //告知当前连接已经退出/停止,由reder退出的信号 ExitChan chan bool //路由管理,用来绑定msgid与api关系 MsgHandle ziface.IMsgHandle //消息类型 TextMessage 或 BinaryMessage 之类 MessageType int `json:"messageType"` // contains filtered or unexported fields }
连接管理
func NewConnection ¶
func NewConnection(server ziface.IServer, conn *zsocket.Conn, connID int64, mh ziface.IMsgHandle) *Connection
初始化连接方法
func (*Connection) GetProperty ¶
func (c *Connection) GetProperty(key string) (p interface{}, err error)
获取连接属性
func (*Connection) GetSnowflakeID ¶
func (c *Connection) GetSnowflakeID() int64
获取snowflake不重复ID生成一个
func (*Connection) GetWsConnection ¶
func (c *Connection) GetWsConnection() *zsocket.Conn
获取当前连接的websocket conn
func (*Connection) RemoteAddr ¶
func (c *Connection) RemoteAddr() net.Addr
获取连接客户端的信息,后续可以加userAgent等
func (*Connection) SendBuffByteMsg ¶
func (c *Connection) SendBuffByteMsg(data []byte)
发送数据,将数据发送给远程客户端(有缓冲)
func (*Connection) SendBuffMsg ¶
func (c *Connection) SendBuffMsg(data string)
发送数据,将数据发送给远程客户端(有缓冲)
func (*Connection) SendByteMsg ¶
func (c *Connection) SendByteMsg(data string)
发送数据,将数据发送给远程客户端(无缓冲)
func (*Connection) SendErrorMsg ¶
func (c *Connection) SendErrorMsg(error string)
发送数据,系统提示信息发送给远程客户端(有缓冲)
func (*Connection) SetProperty ¶
func (c *Connection) SetProperty(key string, value interface{})
设置连接属性
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
func NewLimiter ¶
func NewLimiter(cfg LimiterConfig) *Limiter
func (*Limiter) Config ¶
func (l *Limiter) Config() LimiterConfig
func (*Limiter) HTTPConnStateFunc ¶
func (*Limiter) HTTPConnStateFuncWithErrorHandler ¶
func (*Limiter) SetConfig ¶
func (l *Limiter) SetConfig(c LimiterConfig)
type LimiterConfig ¶
type LimiterConfig struct {
MaxConnsPerClientIP int
}
type Message ¶
type Message struct { Command string `json:"command"` //消息的命令 Type string `json:"type"` //消息的分类 Data json.RawMessage `json:"data"` //消息的内容 }
接收客户端的数据结构
type MsgHandle ¶
type MsgHandle struct { //消息处理 MsgPost map[string]ziface.IRouter //负责worker取任务消息队列 TaskQueue []chan ziface.IRequest //业务工作worker池的worker数量 WorkerPoolSize int64 // contains filtered or unexported fields }
消息处理模块
func (*MsgHandle) DoMsgHandler ¶
执行对应的路由处理方法
func (*MsgHandle) SendMsgToTaskQueue ¶
将消息交给taskqueue处理
func (*MsgHandle) StartOneWorker ¶
启动一个工作流程
type Server ¶
type Server struct { //服务器名称 Name string //服务器协议 ws,wss Scheme string //服务器ip地址 Host string //服务器端口 Port uint32 //协议扩展 Path string //路由管理,用来绑定Command与API关系 MsgHandle ziface.IMsgHandle //连接属性 ConnMgr ziface.IConnManager //连接回调 OnConnStart func(ziface.IConnection) //关闭回调 OnConnStop func(ziface.IConnection) //超过最大连接回调 OnMaxConn func(conn *zsocket.Conn) //ID生成 Snowflake ziface.ISnowflake }
func (*Server) GetSnowflakeMgr ¶
func (s *Server) GetSnowflakeMgr() ziface.ISnowflake
返回 Snowflake管理
func (*Server) SetOnConnStart ¶
func (s *Server) SetOnConnStart(hookStart func(conn ziface.IConnection))
连接之前回调
func (*Server) SetOnConnStop ¶
func (s *Server) SetOnConnStop(hookStop func(conn ziface.IConnection))
关闭之前回调
func (*Server) SetOnMaxConn ¶
超过最大连接回调
Click to show internal directories.
Click to hide internal directories.