Help us shape the future of Go! Take the 2026 Go Developer Survey

gate

package
v2.4.4 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

func NewBuilder

func NewBuilder(opts *Options) *Builder

func (*Builder) Build

func (b *Builder) Build(addr string) (*Client, error)

Build 构建客户端

type Client

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

func NewClient

func NewClient(cli *client.Client) *Client

func (*Client) Bind

func (c *Client) Bind(ctx context.Context, cid, uid int64) (bool, error)

Bind 绑定用户与连接

func (*Client) Broadcast

func (c *Client) Broadcast(ctx context.Context, kind session.Kind, message buffer.Buffer) error

Broadcast 推送广播消息(异步)

func (*Client) Disconnect

func (c *Client) Disconnect(ctx context.Context, kind session.Kind, target int64, force bool) error

Disconnect 断开连接

func (*Client) GetIP

func (c *Client) GetIP(ctx context.Context, kind session.Kind, target int64) (string, bool, error)

GetIP 获取客户端IP

func (*Client) GetState

func (c *Client) GetState(ctx context.Context) (cluster.State, error)

GetState 获取状态

func (*Client) IsOnline

func (c *Client) IsOnline(ctx context.Context, kind session.Kind, target int64) (bool, bool, error)

IsOnline 检测是否在线

func (*Client) Multicast

func (c *Client) Multicast(ctx context.Context, kind session.Kind, targets []int64, message buffer.Buffer) error

Multicast 推送组播消息(异步)

func (*Client) Publish added in v2.3.1

func (c *Client) Publish(ctx context.Context, channel string, message buffer.Buffer) error

Publish 发布频道消息(异步)

func (*Client) Push

func (c *Client) Push(ctx context.Context, kind session.Kind, target int64, message buffer.Buffer) error

Push 推送消息(异步)

func (*Client) SetState

func (c *Client) SetState(ctx context.Context, state cluster.State) error

SetState 设置状态

func (*Client) Stat

func (c *Client) Stat(ctx context.Context, kind session.Kind) (int64, error)

Stat 推送广播消息

func (*Client) Subscribe added in v2.3.1

func (c *Client) Subscribe(ctx context.Context, kind session.Kind, targets []int64, channel string) error

Subscribe 订阅频道

func (*Client) Unbind

func (c *Client) Unbind(ctx context.Context, uid int64) (bool, error)

Unbind 解绑用户与连接

func (*Client) Unsubscribe added in v2.3.1

func (c *Client) Unsubscribe(ctx context.Context, kind session.Kind, targets []int64, channel string) error

Unsubscribe 取消订阅频道

type Options

type Options struct {
	InsID   string       // 实例ID
	InsKind cluster.Kind // 实例类型
}

type Provider

type Provider interface {
	// Bind 绑定用户与网关间的关系
	Bind(ctx context.Context, cid, uid int64) error
	// Unbind 解绑用户与网关间的关系
	Unbind(ctx context.Context, uid int64) error
	// GetIP 获取客户端IP地址
	GetIP(ctx context.Context, kind session.Kind, target int64) (ip string, err error)
	// IsOnline 检测是否在线
	IsOnline(ctx context.Context, kind session.Kind, target int64) (isOnline bool, err error)
	// Stat 统计会话总数
	Stat(ctx context.Context, kind session.Kind) (total int64, err error)
	// Disconnect 断开连接
	Disconnect(ctx context.Context, kind session.Kind, target int64, force bool) error
	// Push 发送消息
	Push(ctx context.Context, kind session.Kind, target int64, message []byte) error
	// Multicast 推送组播消息
	Multicast(ctx context.Context, kind session.Kind, targets []int64, message []byte) (total int64, err error)
	// Broadcast 推送广播消息
	Broadcast(ctx context.Context, kind session.Kind, message []byte) (total int64, err error)
	// Publish 发布频道消息
	Publish(ctx context.Context, channel string, message []byte) (total int64)
	// Subscribe 订阅频道
	Subscribe(ctx context.Context, kind session.Kind, targets []int64, channel string) error
	// Unsubscribe 取消订阅频道
	Unsubscribe(ctx context.Context, kind session.Kind, targets []int64, channel string) error
	// GetState 获取状态
	GetState() (cluster.State, error)
	// SetState 设置状态
	SetState(state cluster.State) error
}

type Server

type Server struct {
	*server.Server
	// contains filtered or unexported fields
}

func NewServer

func NewServer(provider Provider, opts *ServerOptions) (*Server, error)

type ServerOptions added in v2.3.1

type ServerOptions = server.Options

Jump to

Keyboard shortcuts

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