node

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidGID         = link.ErrInvalidGID
	ErrInvalidNID         = link.ErrInvalidNID
	ErrInvalidMessage     = link.ErrInvalidMessage
	ErrInvalidArgument    = link.ErrInvalidArgument
	ErrInvalidSessionKind = link.ErrInvalidSessionKind
	ErrNotFoundUserSource = link.ErrNotFoundUserSource
	ErrReceiveTargetEmpty = link.ErrReceiveTargetEmpty
)

Functions

This section is empty.

Types

type BroadcastArgs

type BroadcastArgs = link.BroadcastArgs

type Context

type Context struct {
	Proxy      *Proxy
	Request    *Request
	Middleware *Middleware
	// contains filtered or unexported fields
}

func (*Context) BindGate

func (c *Context) BindGate(uid int64) error

BindGate 绑定网关

func (*Context) BindNode

func (c *Context) BindNode(nid ...string) error

BindNode 绑定节点

func (*Context) Context

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

Context 获取上线文

func (*Context) Disconnect

func (c *Context) Disconnect(isForce ...bool) error

Disconnect 关闭来自网关的连接

func (*Context) GetIP

func (c *Context) GetIP() (string, error)

GetIP 获取来自网关的连接IP地址

func (*Context) Response

func (c *Context) Response(message interface{}) error

Response 对来自网关或节点的请求进行响应(C/S模型) 使用此方法响应的(消息序列号和消息路由号)与请求的(消息序列号和消息路由号)保持一致

func (*Context) UnbindGate

func (c *Context) UnbindGate() error

UnbindGate 解绑网关

func (*Context) UnbindNode

func (c *Context) UnbindNode() error

UnbindNode 解绑节点

type DeliverArgs

type DeliverArgs struct {
	NID     string   // 接收节点。存在接收节点时,消息会直接投递给接收节点;不存在接收节点时,系统定位用户所在节点,然后投递。
	UID     int64    // 用户ID
	CID     int64    // 连接ID
	Message *Message // 消息
}

type DisconnectArgs

type DisconnectArgs = link.DisconnectArgs

type Event

type Event struct {
	Proxy *Proxy
	Event cluster.Event
	GID   string
	CID   int64
	UID   int64
}

type EventHandler

type EventHandler func(event *Event)

type Events

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

func (*Events) AddEventHandler

func (e *Events) AddEventHandler(event cluster.Event, handler EventHandler)

AddEventHandler 添加事件处理器

type GetIPArgs

type GetIPArgs = link.GetIPArgs

type Message

type Message = link.Message

type Middleware

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

func (*Middleware) Next

func (m *Middleware) Next(ctx *Context)

Next 下一个中间件

func (*Middleware) Skip

func (m *Middleware) Skip(ctx *Context, skip int)

Skip 跳过N个中间件

type MiddlewareHandler

type MiddlewareHandler func(ctx *Context)

type MulticastArgs

type MulticastArgs = link.MulticastArgs

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 WithDecryptor

func WithDecryptor(decryptor crypto.Decryptor) Option

WithDecryptor 设置消息解密器

func WithEncryptor

func WithEncryptor(encryptor crypto.Encryptor) Option

WithEncryptor 设置消息加密器

func WithID

func WithID(id string) Option

WithID 设置实例ID

func WithLocator

func WithLocator(locator locate.Locator) Option

WithLocator 设置定位器

func WithName

func WithName(name string) Option

WithName 设置实例名称

func WithRegistry

func WithRegistry(r registry.Registry) Option

WithRegistry 设置服务注册器

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout 设置RPC调用超时时间

func WithTransporter

func WithTransporter(transporter transport.Transporter) Option

WithTransporter 设置消息传输器

type Proxy

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

func (*Proxy) AskGate

func (p *Proxy) AskGate(ctx context.Context, uid int64, gid string) (string, bool, error)

AskGate 检测用户是否在给定的网关上

func (*Proxy) AskNode

func (p *Proxy) AskNode(ctx context.Context, uid int64, nid string) (string, bool, error)

AskNode 检测用户是否在给定的节点上

func (*Proxy) BindGate

func (p *Proxy) BindGate(ctx context.Context, uid int64, gid string, cid int64) error

BindGate 绑定网关

func (*Proxy) BindNode

func (p *Proxy) BindNode(ctx context.Context, uid int64, nid ...string) error

BindNode 绑定节点 单个用户只能被绑定到某一台节点服务器上,多次绑定会直接覆盖上次绑定 绑定操作会通过发布订阅方式同步到网关服务器和其他相关节点服务器上 NID 为需要绑定的节点ID,默认绑定到当前节点上

func (*Proxy) Broadcast

func (p *Proxy) Broadcast(ctx context.Context, args *BroadcastArgs) (int64, error)

Broadcast 推送广播消息

func (*Proxy) Deliver

func (p *Proxy) Deliver(ctx context.Context, args *DeliverArgs) error

Deliver 投递消息给节点处理

func (*Proxy) Disconnect

func (p *Proxy) Disconnect(ctx context.Context, args *DisconnectArgs) error

Disconnect 断开连接

func (*Proxy) Events

func (p *Proxy) Events() *Events

Events 事件分发器

func (*Proxy) FetchGateList

func (p *Proxy) FetchGateList(ctx context.Context, states ...cluster.State) ([]*registry.ServiceInstance, error)

FetchGateList 拉取网关列表

func (*Proxy) FetchNodeList

func (p *Proxy) FetchNodeList(ctx context.Context, states ...cluster.State) ([]*registry.ServiceInstance, error)

FetchNodeList 拉取节点列表

func (*Proxy) GetIP

func (p *Proxy) GetIP(ctx context.Context, args *GetIPArgs) (string, error)

GetIP 获取客户端IP

func (*Proxy) GetNodeID

func (p *Proxy) GetNodeID() string

GetNodeID 获取当前节点ID

func (*Proxy) GetNodeName

func (p *Proxy) GetNodeName() string

GetNodeName 获取当前节点名称

func (*Proxy) GetNodeState

func (p *Proxy) GetNodeState() cluster.State

GetNodeState 获取当前节点状态

func (*Proxy) Invoke

func (p *Proxy) Invoke(fn func())

Invoke 调用函数(线程安全)

func (*Proxy) LocateGate

func (p *Proxy) LocateGate(ctx context.Context, uid int64) (string, error)

LocateGate 定位用户所在网关

func (*Proxy) LocateNode

func (p *Proxy) LocateNode(ctx context.Context, uid int64) (string, error)

LocateNode 定位用户所在节点

func (*Proxy) Multicast

func (p *Proxy) Multicast(ctx context.Context, args *MulticastArgs) (int64, error)

Multicast 推送组播消息

func (*Proxy) NewServiceClient

func (p *Proxy) NewServiceClient(target string) (transport.ServiceClient, error)

NewServiceClient 新建微服务客户端 target参数可分为两种模式: 直连模式: direct://127.0.0.1:8011 服务发现模式: discovery://service_name

func (*Proxy) Push

func (p *Proxy) Push(ctx context.Context, args *PushArgs) error

Push 推送消息

func (*Proxy) Response

func (p *Proxy) Response(ctx context.Context, req *Request, message interface{}) error

Response 响应消息

func (*Proxy) Router

func (p *Proxy) Router() *Router

Router 路由器

func (*Proxy) SetNodeState

func (p *Proxy) SetNodeState(state cluster.State)

SetNodeState 设置当前节点状态

func (*Proxy) UnbindGate

func (p *Proxy) UnbindGate(ctx context.Context, uid int64) error

UnbindGate 解绑网关

func (*Proxy) UnbindNode

func (p *Proxy) UnbindNode(ctx context.Context, uid int64, nid ...string) error

UnbindNode 解绑节点 解绑时会对解绑节点ID进行校验,不匹配则解绑失败 解绑操作会通过发布订阅方式同步到网关服务器和其他相关节点服务器上 NID 为需要解绑的节点ID,默认解绑当前节点

type PushArgs

type PushArgs = link.PushArgs

type Request

type Request struct {
	GID     string   // 来源网关ID
	NID     string   // 来源节点ID
	CID     int64    // 连接ID
	UID     int64    // 用户ID
	Message *Message // 请求消息
	// contains filtered or unexported fields
}

Request 请求数据

func (*Request) Parse

func (r *Request) Parse(v interface{}) error

Parse 解析消息

type RouteHandler

type RouteHandler func(ctx *Context)

type Router

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

func (*Router) AddRouteHandler

func (r *Router) AddRouteHandler(route int32, stateful bool, handler RouteHandler, middlewares ...MiddlewareHandler)

AddRouteHandler 添加路由处理器

func (*Router) CheckRouteStateful

func (r *Router) CheckRouteStateful(route int32) (stateful bool, exist bool)

CheckRouteStateful 是否为有状态路由

func (*Router) Group

func (r *Router) Group(groups ...func(group *RouterGroup)) *RouterGroup

Group 路由组

func (*Router) HasDefaultRouteHandler

func (r *Router) HasDefaultRouteHandler() bool

HasDefaultRouteHandler 是否存在默认路由处理器

func (*Router) SetDefaultRouteHandler

func (r *Router) SetDefaultRouteHandler(handler RouteHandler)

SetDefaultRouteHandler 设置默认路由处理器,所有未注册的路由均走默认路由处理器

type RouterGroup

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

func (*RouterGroup) AddRouteHandler

func (g *RouterGroup) AddRouteHandler(route int32, stateful bool, handler RouteHandler, middlewares ...MiddlewareHandler) *RouterGroup

AddRouteHandler 添加路由处理器

func (*RouterGroup) Middleware

func (g *RouterGroup) Middleware(middlewares ...MiddlewareHandler) *RouterGroup

Middleware 添加中间件

Jump to

Keyboard shortcuts

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