client

package
v2.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 20 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	component.Base
	// contains filtered or unexported fields
}

Client 客户端组件 负责与服务端建立连接,并提供路由、事件、钩子的注册与消息收发能力

func NewClient

func NewClient(opts ...Option) *Client

NewClient 创建客户端组件 @param opts ...Option 客户端配置项 @return @1 *Client 客户端组件实例

func (*Client) Close added in v2.6.0

func (c *Client) Close()

Close 关闭节点

func (*Client) Destroy

func (c *Client) Destroy()

Destroy 销毁客户端 将状态置为关闭,关闭全部连接并触发Destroy钩子

func (*Client) Init

func (c *Client) Init()

Init 初始化客户端 校验网络客户端与编解码器等必要配置,缺失时直接终止进程,并触发Init钩子

func (*Client) Name

func (c *Client) Name() string

Name 获取客户端名称 @return @1 string 客户端名称

func (*Client) Proxy

func (c *Client) Proxy() *Proxy

Proxy 获取客户端代理 @return @1 *Proxy 客户端代理

func (*Client) Start

func (c *Client) Start()

Start 启动组件

type Conn added in v2.1.0

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

Conn 连接封装 对底层网络连接进行封装,提供消息推送、属性管理与基础信息获取等能力

func (*Conn) Bind added in v2.1.0

func (c *Conn) Bind(uid int64)

Bind 绑定用户ID @param uid int64 用户ID

func (*Conn) Close added in v2.1.0

func (c *Conn) Close() error

Close 关闭连接 @return @1 error 错误信息

func (*Conn) DelAttr added in v2.1.0

func (c *Conn) DelAttr(key any)

DelAttr 删除属性值 @param key any 属性键

func (*Conn) GetAttr added in v2.1.0

func (c *Conn) GetAttr(key any) value.Value

GetAttr 获取属性值 @param key any 属性键 @return @1 value.Value 属性值

func (*Conn) ID added in v2.1.0

func (c *Conn) ID() int64

ID 获取连接ID @return @1 int64 连接ID

func (*Conn) LocalAddr added in v2.1.0

func (c *Conn) LocalAddr() (net.Addr, error)

LocalAddr 获取本地地址 @return @1 net.Addr 本地地址 @return @2 error 错误信息

func (*Conn) LocalIP added in v2.1.0

func (c *Conn) LocalIP() (string, error)

LocalIP 获取本地IP @return @1 string 本地IP地址 @return @2 error 错误信息

func (*Conn) Push added in v2.1.0

func (c *Conn) Push(message *cluster.Message) error

Push 推送消息 对消息数据进行编解码与加密处理后推送给服务端 @param message *cluster.Message 待推送的消息 @return @1 error 错误信息

func (*Conn) RemoteAddr added in v2.1.0

func (c *Conn) RemoteAddr() (net.Addr, error)

RemoteAddr 获取远端地址 @return @1 net.Addr 远端地址 @return @2 error 错误信息

func (*Conn) RemoteIP added in v2.1.0

func (c *Conn) RemoteIP() (string, error)

RemoteIP 获取远端IP @return @1 string 远端IP地址 @return @2 error 错误信息

func (*Conn) SetAttr added in v2.1.0

func (c *Conn) SetAttr(key, value any)

SetAttr 设置属性值 @param key any 属性键 @param value any 属性值

func (*Conn) UID added in v2.1.0

func (c *Conn) UID() int64

UID 获取用户ID @return @1 int64 用户ID

func (*Conn) Unbind added in v2.1.0

func (c *Conn) Unbind()

Unbind 解绑用户ID

type Context

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

Context 路由上下文 封装连接与消息信息,供路由处理器使用

func (*Context) CID

func (c *Context) CID() int64

CID 获取连接ID @return @1 int64 连接ID

func (*Context) Conn added in v2.1.0

func (c *Context) Conn() *Conn

Conn 获取连接 @return @1 *Conn 连接对象

func (*Context) Context

func (c *Context) Context() context.Context

Context 获取上下文 @return @1 context.Context 上下文

func (*Context) Data

func (c *Context) Data() any

Data 获取消息数据 返回未解密的消息原始内容,需要明文时请使用Parse方法 @return @1 any 消息数据

func (*Context) Parse

func (c *Context) Parse(v any) (err error)

Parse 解析消息 对消息数据进行解密并反序列化到指定对象 @param v any 待填充的对象 @return @1 error 解密或反序列化失败时返回的错误

func (*Context) Route

func (c *Context) Route() int32

Route 获取消息路由 @return @1 int32 消息路由

func (*Context) Seq

func (c *Context) Seq() int32

Seq 获取消息序列号 @return @1 int32 消息序列号

func (*Context) UID

func (c *Context) UID() int64

UID 获取用户ID @return @1 int64 用户ID

type DialOption added in v2.1.0

type DialOption func(o *dialOptions)

DialOption 拨号配置项

func WithConnAttr added in v2.1.0

func WithConnAttr(key string, value any) DialOption

WithConnAttr 设置连接属性 @param key string 属性键 @param value any 属性值 @return @1 DialOption 拨号配置项

func WithDialAddr added in v2.1.0

func WithDialAddr(addr string) DialOption

WithDialAddr 设置拨号地址 @param addr string 拨号地址 @return @1 DialOption 拨号配置项

type EventHandler

type EventHandler func(conn *Conn)

EventHandler 客户端事件处理函数

type HookHandler added in v2.1.0

type HookHandler func(proxy *Proxy)

HookHandler 客户端钩子处理函数

type Option

type Option func(o *options)

Option 客户端配置项

func WithClient

func WithClient(client network.Client) Option

WithClient 设置网络客户端 @param client network.Client 网络客户端 @return @1 Option 客户端配置项

func WithCodec

func WithCodec(codec encoding.Codec) Option

WithCodec 设置编解码器 @param codec encoding.Codec 编解码器 @return @1 Option 客户端配置项

func WithContext

func WithContext(ctx context.Context) Option

WithContext 设置上下文 @param ctx context.Context 上下文 @return @1 Option 客户端配置项

func WithEncryptor

func WithEncryptor(encryptor crypto.Encryptor) Option

WithEncryptor 设置消息加密器 @param encryptor crypto.Encryptor 消息加密器 @return @1 Option 客户端配置项

func WithID

func WithID(id string) Option

WithID 设置实例ID @param id string 实例ID @return @1 Option 客户端配置项

func WithName

func WithName(name string) Option

WithName 设置实例名称 @param name string 实例名称 @return @1 Option 客户端配置项

type Proxy

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

Proxy 客户端代理 对外暴露路由、事件、钩子的注册与拨号等能力

func (*Proxy) AddEventListener

func (p *Proxy) AddEventListener(event cluster.Event, handler EventHandler)

AddEventListener 添加事件监听器 @param event cluster.Event 事件类型 @param handler EventHandler 事件处理函数

func (*Proxy) AddHookListener added in v2.1.0

func (p *Proxy) AddHookListener(hook cluster.Hook, handler HookHandler)

AddHookListener 添加钩子监听器 @param hook cluster.Hook 钩子类型 @param handler HookHandler 钩子处理函数

func (*Proxy) AddRouteHandler

func (p *Proxy) AddRouteHandler(route int32, handler RouteHandler)

AddRouteHandler 添加路由处理器 @param route int32 路由号 @param handler RouteHandler 路由处理函数

func (*Proxy) Client added in v2.1.0

func (p *Proxy) Client() network.Client

Client 获取网络客户端 @return @1 network.Client 网络客户端

func (*Proxy) Dial added in v2.1.0

func (p *Proxy) Dial(opts ...DialOption) (*Conn, error)

Dial 拨号 建立与服务端的连接,返回封装后的连接对象 @param opts ...DialOption 拨号配置项 @return @1 *Conn 连接对象 @return @2 error 错误信息

func (*Proxy) ID added in v2.1.0

func (p *Proxy) ID() string

ID 获取客户端ID @return @1 string 客户端ID

func (*Proxy) Name added in v2.1.0

func (p *Proxy) Name() string

Name 获取客户端名称 @return @1 string 客户端名称

func (*Proxy) SetDefaultRouteHandler

func (p *Proxy) SetDefaultRouteHandler(handler RouteHandler)

SetDefaultRouteHandler 设置默认路由处理器,所有未注册的路由均走默认路由处理器 @param handler RouteHandler 默认路由处理函数

type RouteHandler

type RouteHandler func(ctx *Context)

RouteHandler 客户端路由处理函数

Jump to

Keyboard shortcuts

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