gatebase

package
v1.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package basegate handler

Package basegate gate.Session

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSession

func NewSession(data []byte) (gate.ISession, error)

NewSession data必须要有效

func NewSessionByMap

func NewSessionByMap(data map[string]any) (gate.ISession, error)

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 NewDelegate

func NewDelegate(gate gate.IGate) *Delegate

NewDelegate NewDelegate

func (*Delegate) Connect

func (this *Delegate) Connect(a gate.IClientAgent)

当连接建立(握手成功)

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) GetAgentNum

func (this *Delegate) GetAgentNum() int

GetAgentNum

func (*Delegate) OnDestroy

func (this *Delegate) OnDestroy()

OnDestroy

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

func (this *Delegate) OnRpcBroadcast(ctx context.Context, topic string, body []byte) (int64, error)

broadcast message to all session of the gate

func (*Delegate) OnRpcClose

func (this *Delegate) OnRpcClose(ctx context.Context, sessionId string) (bool, error)

Proactively close the connection of session

func (*Delegate) OnRpcConnected

func (this *Delegate) OnRpcConnected(ctx context.Context, sessionId string) (bool, error)

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) OnRpcLoad

func (this *Delegate) OnRpcLoad(ctx context.Context, sessionId string) (gate.ISession, error)

Load the latest 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

func (this *Delegate) OnRpcUnBind(ctx context.Context, sessionId string) (gate.ISession, error)

UnBind the session with the the userId.

func (*Delegate) SessionsRange added in v1.1.7

func (this *Delegate) SessionsRange(f func(key, value any) bool)

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

func (this *GateBase) GetShakeHandler() func(r *http.Request) error

GetShakeHandler 获取建立连接时鉴权器(ws)

func (*GateBase) GetStorageHandler

func (this *GateBase) GetStorageHandler() (storager gate.StorageHandler)

GetStorageHandler 获取Session信息持久化接口

func (*GateBase) GetType

func (this *GateBase) GetType() string

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) OnDestroy

func (this *GateBase) OnDestroy()

func (*GateBase) Options

func (this *GateBase) Options() gate.Options

func (*GateBase) Run

func (this *GateBase) Run(closeSig chan bool)

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

func (this *GateBase) SetShakeHandler(handler func(r *http.Request) error) error

SetShakeHandler 设置建立连接时鉴权器(ws)

func (*GateBase) SetStorageHandler

func (this *GateBase) SetStorageHandler(storager gate.StorageHandler) error

SetStorageHandler 设置Session信息持久化接口

func (*GateBase) Version

func (this *GateBase) Version() string

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) Close added in v1.1.2

func (this *TCPClientAgent) Close()

func (*TCPClientAgent) ConnTime added in v1.1.2

func (this *TCPClientAgent) ConnTime() time.Time

ConnTime 建立连接的时间

func (*TCPClientAgent) GetError added in v1.1.2

func (this *TCPClientAgent) GetError() error

获取最后发生的错误

func (*TCPClientAgent) GetSession added in v1.1.2

func (this *TCPClientAgent) GetSession() gate.ISession

GetSession 管理的ClientSession

func (*TCPClientAgent) Init added in v1.1.2

func (this *TCPClientAgent) Init(impl gate.IClientAgent, gt gate.IGate, conn network.Conn) error

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) OnClose added in v1.1.2

func (this *TCPClientAgent) OnClose() error

func (*TCPClientAgent) OnReadDecodingPack added in v1.1.2

func (this *TCPClientAgent) OnReadDecodingPack() (*gate.Pack, error)

读取数据并解码出Pack

func (*TCPClientAgent) OnWriteEncodingPack added in v1.1.2

func (this *TCPClientAgent) OnWriteEncodingPack(pack *gate.Pack) []byte

OnWriteEncodingPack 处理Pack数据的编码用于发送

func (*TCPClientAgent) RecvNum added in v1.1.2

func (this *TCPClientAgent) RecvNum() int64

RecvNum 接收消息的数量

func (*TCPClientAgent) Run added in v1.1.2

func (this *TCPClientAgent) Run() (err error)

func (*TCPClientAgent) SendNum added in v1.1.2

func (this *TCPClientAgent) SendNum() int64

SendNum 发送消息的数量

func (*TCPClientAgent) SendPack added in v1.1.2

func (this *TCPClientAgent) SendPack(pack *gate.Pack) error

SendPack 提供发送数据包的方法

type WSClientAgent added in v1.1.2

type WSClientAgent struct {
	// contains filtered or unexported fields
}

func (*WSClientAgent) Close added in v1.1.2

func (this *WSClientAgent) Close()

func (*WSClientAgent) ConnTime added in v1.1.2

func (this *WSClientAgent) ConnTime() time.Time

ConnTime 建立连接的时间

func (*WSClientAgent) GetError added in v1.1.2

func (this *WSClientAgent) GetError() error

获取最后发生的错误

func (*WSClientAgent) GetSession added in v1.1.2

func (this *WSClientAgent) GetSession() gate.ISession

GetSession 管理的ClientSession

func (*WSClientAgent) Init added in v1.1.2

func (this *WSClientAgent) Init(impl gate.IClientAgent, gt gate.IGate, conn network.Conn) error

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) OnClose added in v1.1.2

func (this *WSClientAgent) OnClose() error

func (*WSClientAgent) OnReadDecodingPack added in v1.1.2

func (this *WSClientAgent) OnReadDecodingPack() (*gate.Pack, error)

读取数据并解码出Pack

func (*WSClientAgent) OnWriteEncodingPack added in v1.1.2

func (this *WSClientAgent) OnWriteEncodingPack(pack *gate.Pack) []byte

OnWriteEncodingPack 处理Pack数据的编码用于发送

func (*WSClientAgent) RecvNum added in v1.1.2

func (this *WSClientAgent) RecvNum() int64

RecvNum 接收消息的数量

func (*WSClientAgent) Run added in v1.1.2

func (this *WSClientAgent) Run() (err error)

func (*WSClientAgent) SendNum added in v1.1.2

func (this *WSClientAgent) SendNum() int64

SendNum 发送消息的数量

func (*WSClientAgent) SendPack added in v1.1.2

func (this *WSClientAgent) SendPack(pack *gate.Pack) error

SendPack 提供发送数据包的方法

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL