node

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: MIT Imports: 32 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidGID         = errors.New("invalid gate id")
	ErrInvalidNID         = errors.New("invalid node id")
	ErrInvalidSessionKind = errors.New("invalid session kind")
	ErrNotFoundUserSource = errors.New("not found user source")
	ErrReceiveTargetEmpty = errors.New("the receive target is empty")
)

Functions

This section is empty.

Types

type BroadcastArgs

type BroadcastArgs struct {
	Kind    session.Kind // 会话类型,session.Conn 或 session.User
	Route   int32        // 路由ID
	Message interface{}  // 消息内容,接收json、proto、[]byte
}

type DeliverArgs

type DeliverArgs struct {
	GID     string      // 来源网关
	NID     string      // 来源节点
	CID     int64       // 连接ID
	UID     int64       // 用户ID
	Route   int32       // 路由ID
	Message interface{} // 消息内容,接收json、proto、[]byte
}

type EventHandler

type EventHandler func(gid string, uid int64)

type GetIPArgs

type GetIPArgs struct {
	GID    string       // 网关ID,会话类型为用户时可忽略此参数
	Kind   session.Kind // 会话类型,session.Conn 或 session.User
	Target int64        // 会话目标,CID 或 UID
}

type MulticastArgs

type MulticastArgs struct {
	GID     string       // 网关ID,会话类型为用户时可忽略此参数
	Kind    session.Kind // 会话类型,session.Conn 或 session.User
	Targets []int64      // 会话目标,CID 或 UID
	Route   int32        // 路由ID
	Message interface{}  // 消息内容,接收json、proto、[]byte
}

type Node

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

func NewNode

func NewNode(opts ...Option) *Node

func (*Node) Destroy

func (n *Node) Destroy()

Destroy 销毁网关服务器

func (*Node) Init

func (n *Node) Init()

Init 初始化节点

func (*Node) Name

func (n *Node) Name() string

Name 组件名称

func (*Node) Proxy

func (n *Node) Proxy() Proxy

Proxy 获取节点代理

func (*Node) Start

func (n *Node) Start()

Start 启动节点

type Option

type Option func(o *options)

func WithCodec

func WithCodec(codec encoding.Codec) Option

WithCodec 设置编解码器

func WithContext

func WithContext(ctx context.Context) Option

WithContext 设置上下文

func WithGRPCServer

func WithGRPCServer(grpc *grpc.Server) Option

WithGRPCServer 设置GRPC服务器

func WithID

func WithID(id string) Option

WithID 设置实例ID

func WithName

func WithName(name string) Option

WithName 设置实例名称

func WithRedis

func WithRedis(redis redis.Client) Option

WithRedis 设置redis客户端

func WithRegistry

func WithRegistry(r registry.Registry) Option

WithRegistry 设置服务注册

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout 设置RPC调用超时时间

type Proxy

type Proxy interface {
	// AddRoute 添加路由
	AddRoute(route int32, stateful bool, handler RouteHandler)
	// AddEventListener 添加事件监听器
	AddEventListener(event cluster.Event, handler EventHandler)
	// BindGate 绑定网关
	BindGate(ctx context.Context, gid string, cid, uid int64) error
	// UnbindGate 绑定网关
	UnbindGate(ctx context.Context, uid int64) error
	// BindNode 绑定节点
	BindNode(ctx context.Context, uid int64) error
	// UnbindNode 解绑节点
	UnbindNode(ctx context.Context, uid int64) error
	// LocateGate 定位用户所在网关
	LocateGate(ctx context.Context, uid int64) (string, error)
	// LocateNode 定位用户所在节点
	LocateNode(ctx context.Context, uid int64) (string, error)
	// GetIP 获取客户端IP
	GetIP(ctx context.Context, args *GetIPArgs) (string, error)
	// Push 推送消息
	Push(ctx context.Context, args *PushArgs) error
	// Response 响应消息
	Response(ctx context.Context, req Request, message interface{}) error
	// Multicast 推送组播消息
	Multicast(ctx context.Context, args *MulticastArgs) (int64, error)
	// Broadcast 推送广播消息
	Broadcast(ctx context.Context, args *BroadcastArgs) (int64, error)
}

type PushArgs

type PushArgs struct {
	GID     string       // 网关ID,会话类型为用户时可忽略此参数
	Kind    session.Kind // 会话类型,session.Conn 或 session.User
	Target  int64        // 会话目标,CID 或 UID
	Route   int32        // 路由ID
	Message interface{}  // 消息内容,接收json、proto、[]byte
}

type Request

type Request interface {
	// GID 获取来源网关ID
	GID() string
	// NID 获取来源节点ID
	NID() string
	// CID 获取来源连接ID
	CID() int64
	// UID 获取来源用户ID
	UID() int64
	// Route 获取路由
	Route() int32
	// Parse 解析请求
	Parse(v interface{}) error
	// Context 获取上线文
	Context() context.Context
	// Response 响应请求
	Response(message interface{}) error
}

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