Documentation
¶
Overview ¶
Package basegate handler
Package basegate gate.Session
Index ¶
- func NewSession(data []byte) (gate.ISession, error)
- func NewSessionByMap(data map[string]any) (gate.ISession, error)
- func NewTCPClientAgent() gate.IClientAgent
- func NewWSClientAgent() gate.IClientAgent
- type Delegate
- func (this *Delegate) Connect(a gate.IClientAgent)
- func (this *Delegate) DisConnect(a gate.IClientAgent)
- func (this *Delegate) GetAgent(sessionId string) (gate.IClientAgent, error)
- func (this *Delegate) GetAgentNum() int
- func (this *Delegate) OnDestroy()
- func (this *Delegate) OnRpcBind(ctx context.Context, sessionId string, userId string) (gate.ISession, error)
- func (this *Delegate) OnRpcBroadcast(ctx context.Context, topic string, body []byte) (int64, error)
- func (this *Delegate) OnRpcClose(ctx context.Context, sessionId string) (bool, error)
- func (this *Delegate) OnRpcConnected(ctx context.Context, sessionId string) (bool, error)
- func (this *Delegate) OnRpcDel(ctx context.Context, sessionId string, key string) (gate.ISession, error)
- func (this *Delegate) OnRpcLoad(ctx context.Context, sessionId string) (gate.ISession, error)
- func (this *Delegate) OnRpcPush(ctx context.Context, sessionId string, settings map[string]string) (gate.ISession, error)
- func (this *Delegate) OnRpcSend(ctx context.Context, sessionId string, topic string, body []byte) (bool, error)
- func (this *Delegate) OnRpcSet(ctx context.Context, sessionId string, key string, value string) (gate.ISession, error)
- func (this *Delegate) OnRpcUnBind(ctx context.Context, sessionId string) (gate.ISession, error)
- func (this *Delegate) SessionsRange(f func(key, value any) bool)
- type GateBase
- func (this *GateBase) GetAgentLearner() gate.IAgentLearner
- func (this *GateBase) GetDelegater() gate.IDelegater
- func (this *GateBase) GetRecvPackHandler() gate.FunRecvPackHandler
- func (this *GateBase) GetRouteHandler() gate.RouteHandler
- func (this *GateBase) GetSendMessageHook() gate.FunSendMessageHook
- func (this *GateBase) GetSessionLearner() gate.ISessionLearner
- func (this *GateBase) GetShakeHandler() func(r *http.Request) error
- func (this *GateBase) GetStorageHandler() (storager gate.StorageHandler)
- func (this *GateBase) GetType() string
- func (this *GateBase) Init(subclass app.IRPCModule, settings *conf.ModuleSettings, opts ...gate.Option)
- func (this *GateBase) OnAppConfigurationLoaded()
- func (this *GateBase) OnConfChanged(settings *conf.ModuleSettings)
- func (this *GateBase) OnDestroy()
- func (this *GateBase) Options() gate.Options
- func (this *GateBase) Run(closeSig chan bool)
- func (this *GateBase) SetAgentCreater(cfunc func(netTyp string) gate.IClientAgent) error
- func (this *GateBase) SetAgentLearner(learner gate.IAgentLearner) error
- func (this *GateBase) SetDelegater(handler gate.IDelegater) error
- func (this *GateBase) SetRecvPackHandler(handler gate.FunRecvPackHandler) error
- func (this *GateBase) SetRouteHandler(router gate.RouteHandler) error
- func (this *GateBase) SetSendMessageHook(hook gate.FunSendMessageHook) error
- func (this *GateBase) SetSessionLearner(learner gate.ISessionLearner) error
- func (this *GateBase) SetShakeHandler(handler func(r *http.Request) error) error
- func (this *GateBase) SetStorageHandler(storager gate.StorageHandler) error
- func (this *GateBase) Version() string
- type SessionImp
- type TCPClientAgent
- func (this *TCPClientAgent) Close()
- func (this *TCPClientAgent) ConnTime() time.Time
- func (this *TCPClientAgent) GetError() error
- func (this *TCPClientAgent) GetSession() gate.ISession
- func (this *TCPClientAgent) Init(impl gate.IClientAgent, gt gate.IGate, conn network.Conn) error
- func (this *TCPClientAgent) IsClosed() bool
- func (this *TCPClientAgent) IsShaked() bool
- func (this *TCPClientAgent) OnClose() error
- func (this *TCPClientAgent) OnReadDecodingPack() (*gate.Pack, error)
- func (this *TCPClientAgent) OnWriteEncodingPack(pack *gate.Pack) []byte
- func (this *TCPClientAgent) RecvNum() int64
- func (this *TCPClientAgent) Run() (err error)
- func (this *TCPClientAgent) SendNum() int64
- func (this *TCPClientAgent) SendPack(pack *gate.Pack) error
- type WSClientAgent
- func (this *WSClientAgent) Close()
- func (this *WSClientAgent) ConnTime() time.Time
- func (this *WSClientAgent) GetError() error
- func (this *WSClientAgent) GetSession() gate.ISession
- func (this *WSClientAgent) Init(impl gate.IClientAgent, gt gate.IGate, conn network.Conn) error
- func (this *WSClientAgent) IsClosed() bool
- func (this *WSClientAgent) IsShaked() bool
- func (this *WSClientAgent) OnClose() error
- func (this *WSClientAgent) OnReadDecodingPack() (*gate.Pack, error)
- func (this *WSClientAgent) OnWriteEncodingPack(pack *gate.Pack) []byte
- func (this *WSClientAgent) RecvNum() int64
- func (this *WSClientAgent) Run() (err error)
- func (this *WSClientAgent) SendNum() int64
- func (this *WSClientAgent) SendPack(pack *gate.Pack) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewSessionByMap ¶
NewSessionByMap data可以为空则构造一个空的Session
func NewTCPClientAgent ¶ added in v1.1.2
func NewTCPClientAgent() gate.IClientAgent
func NewWSClientAgent ¶ added in v1.1.2
func NewWSClientAgent() gate.IClientAgent
Types ¶
type Delegate ¶
type Delegate struct {
// contains filtered or unexported fields
}
Delegate Delegate(gate.IAgentLearner,gate.IDelegater)
func (*Delegate) DisConnect ¶
func (this *Delegate) DisConnect(a gate.IClientAgent)
当连接关闭(客户端主动关闭或者异常断开)
func (*Delegate) GetAgent ¶
func (this *Delegate) GetAgent(sessionId string) (gate.IClientAgent, error)
GetAgent
func (*Delegate) OnRpcBind ¶
func (this *Delegate) OnRpcBind(ctx context.Context, sessionId string, userId string) (gate.ISession, error)
Bind the session with the the userId.
func (*Delegate) OnRpcBroadcast ¶
broadcast message to all session of the gate
func (*Delegate) OnRpcClose ¶
Proactively close the connection of session
func (*Delegate) OnRpcConnected ¶
check connect is normal for the session
func (*Delegate) OnRpcDel ¶
func (this *Delegate) OnRpcDel(ctx context.Context, sessionId string, key string) (gate.ISession, error)
Del value from the session.
func (*Delegate) OnRpcPush ¶
func (this *Delegate) OnRpcPush(ctx context.Context, sessionId string, settings map[string]string) (gate.ISession, error)
Push the session with the the userId.
func (*Delegate) OnRpcSend ¶
func (this *Delegate) OnRpcSend(ctx context.Context, sessionId string, topic string, body []byte) (bool, error)
Send message to the session.
func (*Delegate) OnRpcSet ¶
func (this *Delegate) OnRpcSet(ctx context.Context, sessionId string, key string, value string) (gate.ISession, error)
Set values (one or many) for the session.
func (*Delegate) OnRpcUnBind ¶
UnBind the session with the the userId.
func (*Delegate) SessionsRange ¶ added in v1.1.7
SessionsRange
type GateBase ¶
type GateBase struct {
module.ModuleBase
// contains filtered or unexported fields
}
func (*GateBase) GetAgentLearner ¶
func (this *GateBase) GetAgentLearner() gate.IAgentLearner
SetAgentLearner 获取客户端连接和断开的监听器(内部用)
func (*GateBase) GetDelegater ¶
func (this *GateBase) GetDelegater() gate.IDelegater
GetDelegater 获取代理处理器
func (*GateBase) GetRecvPackHandler ¶ added in v1.1.3
func (this *GateBase) GetRecvPackHandler() gate.FunRecvPackHandler
GetRecvPackHandler 获取接收数据包处理接口
func (*GateBase) GetRouteHandler ¶
func (this *GateBase) GetRouteHandler() gate.RouteHandler
GetRouteHandler 获取路由接口
func (*GateBase) GetSendMessageHook ¶
func (this *GateBase) GetSendMessageHook() gate.FunSendMessageHook
GetSendMessageHook 获取发送消息时的钩子回调
func (*GateBase) GetSessionLearner ¶
func (this *GateBase) GetSessionLearner() gate.ISessionLearner
GetSessionLearner 获取客户端连接和断开的监听器
func (*GateBase) GetShakeHandler ¶
GetShakeHandler 获取建立连接时鉴权器(ws)
func (*GateBase) GetStorageHandler ¶
func (this *GateBase) GetStorageHandler() (storager gate.StorageHandler)
GetStorageHandler 获取Session信息持久化接口
func (*GateBase) Init ¶
func (this *GateBase) Init(subclass app.IRPCModule, settings *conf.ModuleSettings, opts ...gate.Option)
func (*GateBase) OnAppConfigurationLoaded ¶
func (this *GateBase) OnAppConfigurationLoaded()
func (*GateBase) OnConfChanged ¶
func (this *GateBase) OnConfChanged(settings *conf.ModuleSettings)
func (*GateBase) SetAgentCreater ¶
func (this *GateBase) SetAgentCreater(cfunc func(netTyp string) gate.IClientAgent) error
设置创建客户端Agent的函数
func (*GateBase) SetAgentLearner ¶
func (this *GateBase) SetAgentLearner(learner gate.IAgentLearner) error
SetAgentLearner 设置客户端连接和断开的监听器(内部用)
func (*GateBase) SetDelegater ¶ added in v1.1.4
func (this *GateBase) SetDelegater(handler gate.IDelegater) error
SetGateHandler 设置代理处理器
func (*GateBase) SetRecvPackHandler ¶ added in v1.1.3
func (this *GateBase) SetRecvPackHandler(handler gate.FunRecvPackHandler) error
SetRecvPackHandler 设置接收数据包处理接口
func (*GateBase) SetRouteHandler ¶
func (this *GateBase) SetRouteHandler(router gate.RouteHandler) error
SetRouteHandler 设置路由接口
func (*GateBase) SetSendMessageHook ¶
func (this *GateBase) SetSendMessageHook(hook gate.FunSendMessageHook) error
SetsendMessageHook 设置发送消息时的钩子回调
func (*GateBase) SetSessionLearner ¶
func (this *GateBase) SetSessionLearner(learner gate.ISessionLearner) error
SetSessionLearner 设置客户端连接和断开的监听器
func (*GateBase) SetShakeHandler ¶
SetShakeHandler 设置建立连接时鉴权器(ws)
func (*GateBase) SetStorageHandler ¶
func (this *GateBase) SetStorageHandler(storager gate.StorageHandler) error
SetStorageHandler 设置Session信息持久化接口
type SessionImp ¶
type SessionImp struct {
IP string `msgpack:"ip,omitempty" json:"ip,omitempty"`
Network string `msgpack:"network,omitempty" json:"network,omitempty"`
UserId string `msgpack:"user_id,omitempty" json:"user_id,omitempty"`
SessionId string `msgpack:"session_id,omitempty" json:"session_id,omitempty"`
ServerId string `msgpack:"server_id,omitempty" json:"server_id,omitempty"`
TraceId string `msgpack:"trace_id,omitempty" json:"trace_id,omitempty"`
SpanId string `msgpack:"span_id,omitempty" json:"span_id,omitempty"`
Settings map[string]string `msgpack:"settings,omitempty" json:"settings,omitempty"`
}
type TCPClientAgent ¶ added in v1.1.2
type TCPClientAgent struct {
// contains filtered or unexported fields
}
func (*TCPClientAgent) GetError ¶ added in v1.1.2
func (this *TCPClientAgent) GetError() error
获取最后发生的错误
func (*TCPClientAgent) GetSession ¶ added in v1.1.2
GetSession 管理的ClientSession
func (*TCPClientAgent) IsClosed ¶ added in v1.1.2
func (this *TCPClientAgent) IsClosed() bool
IsClosed 是否关闭了
func (*TCPClientAgent) IsShaked ¶ added in v1.1.2
func (this *TCPClientAgent) IsShaked() bool
IsShaked 连接就绪(握手/认证...)
func (*TCPClientAgent) OnReadDecodingPack ¶ added in v1.1.2
func (this *TCPClientAgent) OnReadDecodingPack() (*gate.Pack, error)
读取数据并解码出Pack
func (*TCPClientAgent) OnWriteEncodingPack ¶ added in v1.1.2
OnWriteEncodingPack 处理Pack数据的编码用于发送
func (*TCPClientAgent) RecvNum ¶ added in v1.1.2
func (this *TCPClientAgent) RecvNum() int64
RecvNum 接收消息的数量
type WSClientAgent ¶ added in v1.1.2
type WSClientAgent struct {
// contains filtered or unexported fields
}
func (*WSClientAgent) GetError ¶ added in v1.1.2
func (this *WSClientAgent) GetError() error
获取最后发生的错误
func (*WSClientAgent) GetSession ¶ added in v1.1.2
GetSession 管理的ClientSession
func (*WSClientAgent) IsClosed ¶ added in v1.1.2
func (this *WSClientAgent) IsClosed() bool
IsClosed 是否关闭了
func (*WSClientAgent) IsShaked ¶ added in v1.1.2
func (this *WSClientAgent) IsShaked() bool
IsShaked 连接就绪(握手/认证...)
func (*WSClientAgent) OnReadDecodingPack ¶ added in v1.1.2
func (this *WSClientAgent) OnReadDecodingPack() (*gate.Pack, error)
读取数据并解码出Pack
func (*WSClientAgent) OnWriteEncodingPack ¶ added in v1.1.2
OnWriteEncodingPack 处理Pack数据的编码用于发送
func (*WSClientAgent) RecvNum ¶ added in v1.1.2
func (this *WSClientAgent) RecvNum() int64
RecvNum 接收消息的数量