node

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2023 License: MIT Imports: 20 Imported by: 4

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 added in v0.0.10

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

func (*Context) BindGate added in v0.0.10

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

BindGate 绑定网关

func (*Context) BindNode added in v0.0.10

func (c *Context) BindNode() error

BindNode 绑定节点

func (*Context) Context added in v0.0.10

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

Context 获取上线文

func (*Context) Disconnect added in v0.0.10

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

Disconnect 关闭来自网关的连接

func (*Context) GetIP added in v0.0.10

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

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

func (*Context) Response added in v0.0.10

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

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

func (*Context) UnbindGate added in v0.0.10

func (c *Context) UnbindGate() error

UnbindGate 解绑网关

func (*Context) UnbindNode added in v0.0.10

func (c *Context) UnbindNode() error

UnbindNode 解绑节点

type DeliverArgs

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

type DisconnectArgs added in v0.0.3

type DisconnectArgs = link.DisconnectArgs

type Event added in v0.0.10

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

type EventHandler

type EventHandler func(event *Event)

type Events added in v0.0.10

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

func (*Events) AddEventHandler added in v0.0.10

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

AddEventHandler 添加事件处理器

type GetIPArgs

type GetIPArgs = link.GetIPArgs

type Message added in v0.0.4

type Message = link.Message

type Middleware added in v0.0.10

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

func (*Middleware) Next added in v0.0.10

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

Next 下一个中间件

func (*Middleware) Skip added in v0.0.10

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

Skip 跳过N个中间件

type MiddlewareHandler added in v0.0.10

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 added in v0.0.6

func WithDecryptor(decryptor crypto.Decryptor) Option

WithDecryptor 设置消息解密器

func WithEncryptor added in v0.0.6

func WithEncryptor(encryptor crypto.Encryptor) Option

WithEncryptor 设置消息加密器

func WithID

func WithID(id string) Option

WithID 设置实例ID

func WithLocator added in v0.0.3

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 added in v0.0.4

func WithTransporter(transporter transport.Transporter) Option

WithTransporter 设置消息传输器

type Proxy

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

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 added in v0.0.6

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

Deliver 投递消息给节点处理

func (*Proxy) Disconnect added in v0.0.3

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

Disconnect 断开连接

func (*Proxy) Events added in v0.0.10

func (p *Proxy) Events() *Events

Events 事件分发器

func (*Proxy) FetchGateList added in v0.0.3

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

FetchGateList 拉取网关列表

func (*Proxy) FetchNodeList added in v0.0.3

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 added in v0.0.10

func (p *Proxy) GetNodeID() string

GetNodeID 获取当前节点ID

func (*Proxy) GetNodeName added in v0.0.10

func (p *Proxy) GetNodeName() string

GetNodeName 获取当前节点名称

func (*Proxy) GetNodeState added in v0.0.10

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

GetNodeState 获取当前节点状态

func (*Proxy) Invoke added in v0.0.10

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 added in v0.0.17

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 added in v0.0.10

func (p *Proxy) Router() *Router

Router 路由器

func (*Proxy) SetNodeState added in v0.0.10

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 added in v0.0.10

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

func (*Router) AddRouteHandler added in v0.0.10

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

AddRouteHandler 添加路由处理器

func (*Router) CheckRouteStateful added in v0.0.10

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

CheckRouteStateful 是否为有状态路由

func (*Router) Group added in v0.0.10

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

Group 路由组

func (*Router) HasDefaultRouteHandler added in v0.0.10

func (r *Router) HasDefaultRouteHandler() bool

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

func (*Router) SetDefaultRouteHandler added in v0.0.10

func (r *Router) SetDefaultRouteHandler(handler RouteHandler)

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

type RouterGroup added in v0.0.10

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

func (*RouterGroup) AddRouteHandler added in v0.0.10

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

AddRouteHandler 添加路由处理器

func (*RouterGroup) Middleware added in v0.0.10

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