router

package
v0.1.51 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: LGPL-2.1 Imports: 28 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Name      = self.Name
	Using     = self.Using
	Install   = self.Install
	Uninstall = self.Uninstall
)
View Source
var (
	ErrGroupExisted = errors.New("router: group already existed")
	ErrGroupDeleted = errors.New("router: group already deleted")
)
View Source
var With _Option

Functions

This section is empty.

Types

type IGroup

type IGroup interface {
	context.Context
	// GetId 获取分组Id
	GetId() uid.Id
	// AddEntities 添加实体
	AddEntities(ctx context.Context, entIds ...uid.Id) error
	// RemoveEntities 删除实体
	RemoveEntities(ctx context.Context, entIds ...uid.Id) error
	// RenewEntities 刷新所有实体
	RenewEntities(ctx context.Context, entIds ...uid.Id) error
	// RangeEntities 遍历所有实体
	RangeEntities(fun generic.Func1[uid.Id, bool])
	// CountEntities 获取实体数量
	CountEntities() int
	// RefreshTTL 刷新TTL
	RefreshTTL(ctx context.Context) error
	// SendData 发送数据
	SendData(data []byte) error
	// SendEvent 发送自定义事件
	SendEvent(event transport.Event[gtp.MsgReader]) error
	// SendDataChan 发送数据的channel
	SendDataChan() chan<- binaryutil.RecycleBytes
	// SendEventChan 发送自定义事件的channel
	SendEventChan() chan<- transport.Event[gtp.MsgReader]
}

IGroup 分组接口

type IMapping added in v0.1.45

type IMapping interface {
	context.Context
	// GetEntity 获取实体
	GetEntity() ec.ConcurrentEntity
	// GetSession 获取会话
	GetSession() gate.ISession
	// GetCliAddr 获取客户端地址
	GetCliAddr() string
}

IMapping 映射

type IRouter

type IRouter interface {
	// Mapping 路由映射
	Mapping(entityId, sessionId uid.Id) (IMapping, error)
	// CleanEntity 清理实体路由信息
	CleanEntity(entityId uid.Id)
	// CleanSession 清理会话路由信息
	CleanSession(sessionId uid.Id)
	// LookupEntity 查找实体
	LookupEntity(sessionId uid.Id) (ec.ConcurrentEntity, string, bool)
	// LookupSession 查找会话
	LookupSession(entityId uid.Id) (gate.ISession, bool)
	// GetGroup 查询分组
	GetGroup(groupId uid.Id) (IGroup, bool)
	// GetOrAddGroup 查询或添加分组
	GetOrAddGroup(ctx context.Context, groupId uid.Id, ttl time.Duration, entIds ...uid.Id) (IGroup, error)
	// GetAndDeleteGroup 查询并删除分组
	GetAndDeleteGroup(ctx context.Context, groupId uid.Id) (IGroup, bool)
	// AddGroup 添加分组
	AddGroup(ctx context.Context, groupId uid.Id, ttl time.Duration, entIds ...uid.Id) (IGroup, error)
	// DeleteGroup 删除分组
	DeleteGroup(ctx context.Context, groupId uid.Id)
	// RangeGroups 遍历所有分组
	RangeGroups(fun generic.Func1[IGroup, bool])
	// CountGroups 统计所有分组数量
	CountGroups() int
}

IRouter 路由器接口

type RouterOptions

type RouterOptions struct {
	EtcdClient             *clientv3.Client
	EtcdConfig             *clientv3.Config
	KeyPrefix              string
	WatchChanSize          int
	GroupTTL               time.Duration
	GroupAutoRefreshTTL    bool
	GroupSendDataChanSize  int
	GroupSendEventChanSize int
	CustomUsername         string
	CustomPassword         string
	CustomAddresses        []string
	CustomTLSConfig        *tls.Config
}

Jump to

Keyboard shortcuts

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