client

package
v0.0.0-...-457ba4f Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClientShut       = errors.New("client is shut")
	ErrConnectionClosed = errors.New("connection closed")
)

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(opts ...Option) *Client

func (*Client) Destroy

func (c *Client) Destroy()

Destroy 销毁组件

func (*Client) Init

func (c *Client) Init()

Init 初始化节点

func (*Client) Name

func (c *Client) Name() string

Name 组件名称

func (*Client) Proxy

func (c *Client) Proxy() Proxy

Proxy 获取节点代理

func (*Client) Start

func (c *Client) Start()

Start 启动组件

type EventHandler

type EventHandler func(proxy Proxy)

type Option

type Option func(o *options)

func WithClient

func WithClient(client network.Client) Option

WithClient 设置客户端

func WithCodec

func WithCodec(codec encoding.Codec) Option

WithCodec 设置编解码器

func WithContext

func WithContext(ctx context.Context) Option

WithContext 设置上下文

func WithID

func WithID(id string) Option

WithID 设置实例ID

func WithName

func WithName(name string) Option

WithName 设置实例名称

type Proxy

type Proxy interface {
	// GetClientID 获取客户端ID
	GetClientID() string
	// AddRouteHandler 添加路由处理器
	AddRouteHandler(route int32, handler RouteHandler)
	// SetDefaultRouteHandler 设置默认路由处理器,所有未注册的路由均走默认路由处理器
	SetDefaultRouteHandler(handler RouteHandler)
	// AddEventListener 添加事件监听器
	AddEventListener(event int32, handler EventHandler)
	// Bind 绑定用户ID
	Bind(uid int64) error
	// Unbind 解绑用户ID
	Unbind() error
	// Push 推送消息
	Push(seq, route int32, message interface{}) error
	// Reconnect 重新连接
	Reconnect() error
	// Disconnect 断开连接
	Disconnect() error
}

type Request

type Request interface {
	// CID 获取来源连接ID
	CID() int64
	// UID 获取来源用户ID
	UID() int64
	// Seq 获取消息序列号
	Seq() int32
	// Route 获取路由
	Route() int32
	// Data 获取数据
	Data() interface{}
	// Parse 解析请求
	Parse(v interface{}) error
	// Context 获取上线文
	Context() context.Context
	// Proxy 获取代理
	Proxy() Proxy
}

type RouteHandler

type RouteHandler func(req Request)

Jump to

Keyboard shortcuts

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