Documentation
¶
Index ¶
- Variables
- func ToString(value any) string
- type BeforeUpgradeHandle
- type Client
- type CloseHandler
- type Codec
- type Conn
- type ConnMgr
- type ConnState
- type ConnectHandler
- type DisconnectHandler
- type IRouter
- type IRouterInfo
- type MateCache
- type MetaStorage
- type Packer
- type ReceiveHandler
- type Server
- type SocketServer
- type StartHandler
Constants ¶
This section is empty.
Variables ¶
Functions ¶
Types ¶
type BeforeUpgradeHandle ¶
type BeforeUpgradeHandle func(w http.ResponseWriter, r *http.Request) bool
type Client ¶
type Client interface {
// Dial 拨号连接
Dial() (Conn, error)
// OnConnect 监听连接打开
OnConnect(handler ConnectHandler)
// OnReceive 监听接收消息
OnReceive(handler ReceiveHandler)
// OnDisconnect 监听连接断开
OnDisconnect(handler DisconnectHandler)
}
type CloseHandler ¶
type CloseHandler func()
type Conn ¶
type Conn interface {
// ID 获取连接ID
ID() string
// UID 获取用户ID
UID() int
// Bind 绑定用户ID
Bind(uid int)
// Unbind 解绑用户ID
Unbind()
// Send 发送消息(同步)
Send(data []byte, msgType ...int) error
// Push 发送消息(异步)
Push(data []byte, msgType ...int) (err error)
// PushAll 全网关发送(异步)
PushAll(data []byte, smgType ...int) error
// State 获取连接状态
State() ConnState
// Close 关闭连接
Close(isForce ...bool) error
// LocalIP 获取本地IP
LocalIP() (string, error)
// LocalAddr 获取本地地址
LocalAddr() (net.Addr, error)
// RemoteIP 获取远端IP
RemoteIP() (string, error)
// RemoteAddr 获取远端地址
RemoteAddr() (net.Addr, error)
MateCache
}
type ConnectHandler ¶
type ConnectHandler func(conn Conn)
type DisconnectHandler ¶
type DisconnectHandler func(conn Conn)
type IRouter ¶
type IRouter interface {
RegisterHandle(msgId int32, param interface{}, fn interface{})
RegisterMsg(msgId int32, msg interface{})
LoadRouterInfo(msgId int32) IRouterInfo
LoadMsgId(responseMsg interface{}) int32
}
type IRouterInfo ¶
type MetaStorage ¶
type MetaStorage interface {
Storage(uid any, m map[string]any) error
Delete(uid any) error
Select(uid any) (map[string]any, error)
}
MetaStorage 缓存用户零时数据,用作断线重连等
type ReceiveHandler ¶
type Server ¶
type Server interface {
// Addr 监听地址
Addr() string
// Start 启动服务器
Start() error
// Stop 关闭服务器
Stop() error
// OnStart 监听服务器启动
OnStart(handler StartHandler)
// OnStop 监听服务器关闭
OnStop(handler CloseHandler)
}
type SocketServer ¶
type SocketServer interface {
// Addr 监听地址
Addr() string
// Start 启动服务器
Start() error
// Stop 关闭服务器
Stop() error
// OnStart 监听服务器启动
OnStart(handler StartHandler)
// OnStop 监听服务器关闭
OnStop(handler CloseHandler)
// OnConnect 监听连接打开
OnConnect(handler ConnectHandler)
// OnReceive 监听接收消息
OnReceive(handler ReceiveHandler)
// OnDisconnect 监听连接断开
OnDisconnect(handler DisconnectHandler)
//GetConnMgr 获取连接管理器
GetConnMgr() ConnMgr
// Protocol 协议
Protocol() string
// SetCacheStorage 设置缓存存储函数
SetCacheStorage(storage MetaStorage)
}
type StartHandler ¶
type StartHandler func()
Click to show internal directories.
Click to hide internal directories.