Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IConnManager ¶
type IConnManager interface {
//添加连接
Add(conn IConnection)
//删除连接
Remove(conn IConnection)
//根据id查找连接
Get(connID int64) (IConnection, error)
//总连接个数
Len() int
//清除全部连接
ClearConn()
}
连接管理
type IConnection ¶
type IConnection interface {
//停止连接,结束当前连接工作
Stop()
//获取当前连接的websocket conn
GetWsConnection() *zsocket.Conn
//获取当前连接的id
GetConnID() int64
//获取一个不重复ID
GetSnowflakeID() int64
//获取连接客户端的状态 ip 端口
RemoteAddr() net.Addr
//发送数据,将数据发送给远程客户端(无缓冲)
SendMsg(data string)
//发送数据,将数据发送给远程客户端(有缓冲)
SendBuffMsg(data string)
//发送数据,将数据发送给远程客户端(无缓冲)
SendByteMsg(data string)
//发送数据,将数据发送给远程客户端(有缓冲)
SendBuffByteMsg(data []byte)
//发送数据,系统提示信息发送给远程客户端(有缓冲)
SendErrorMsg(error string)
//设置连接属性
SetProperty(key string, value interface{})
//获取连接属性
GetProperty(key string) (interface{}, error)
//移除设置属性
RemoveProperty(key string)
//设置当前消息类型
SetMessageType(mt int)
//得到当前消息类型
GetMessageType() int
//设置加入房间
SetJoinRooms(room string)
//删除加入房间
DelJoinRoomById(room string)
//是否加入房间
IsJoinRoom(room string) bool
//获取加入房间
GetJoinRooms() map[string]bool
//是否关闭
IsClosed() bool
//更新心跳
KeepAlive()
}
连接管理
type IMessage ¶
type IMessage interface {
GetCommand() string //获取消息command
GetType() string
GetData() json.RawMessage //获取消息内容
SetCommand(string) //获取消息命令
SetType(string) //获取消息命令类型
SetData(json.RawMessage) //获取消息数据
}
将请求的一个消息封装到message中,定义抽象层接口
type IMsgHandle ¶
type IMsgHandle interface {
//执行对应的路由处理方法
DoMsgHandler(request IRequest)
//添加路由
SetRouter(command string, ctype string, name string, router IRouter)
//启动一个worker工作池 只能发生一次
StartWorkerPool()
//将消息交给taskqueue处理
SendMsgToTaskQueue(request IRequest)
}
消息管理抽象层
type IRequest ¶
type IRequest interface {
//得到当前连接
GetConnection() IConnection
//得到请求数据
GetData() json.RawMessage
//获取请求的消息命令
GetCommand() string
//获取请求的消息命令类型
GetType() string
}
把客户端数据包装成一个requst
type IRouter ¶
type IRouter interface {
//处理业务之前
PreHandle(request IRequest)
//处理业务
Handle(request IRequest)
//处理业务之后
PostHandle(request IRequest)
}
路由接口(参考beego名字重新命名下)
type IServer ¶
type IServer interface {
//启动
Start()
//停止
Stop()
//运行状态
Serve()
//添加路由
SetRouter(command string, ctype string, name string, router IRouter)
//返回 连接管理
GetConnMgr() IConnManager
//返回 GetSnowflake管理
GetSnowflakeMgr() ISnowflake
//连接之前回调Serve
SetOnConnStart(func(conn IConnection))
//关闭之前回调
SetOnConnStop(func(conn IConnection))
//调用连接之前
CallOnConnStart(conn IConnection)
//调用关闭之前
CallOnConnStop(conn IConnection)
//超过最大连接回调
SetOnMaxConn(func(Conn *zsocket.Conn))
//超过最大连接回调
CallOnMaxConn(conn *zsocket.Conn)
}
接口定义
Click to show internal directories.
Click to hide internal directories.