Documentation
¶
Overview ¶
* User: cr-mao Date: 2023/8/19 20:16 Email: crmao@qq.com Desc: config_const.go
* User: cr-mao Date: 2023/8/21 15:03 Email: crmao@qq.com Desc: gate_client.go
* User: cr-mao Date: 2023/8/21 21:34 Email: crmao@qq.com Desc: node_grpc_client.go
* User: cr-mao Date: 2023/8/21 20:47 Email: crmao@qq.com Desc: request.go
* User: cr-mao Date: 2023/8/21 21:07 Email: crmao@qq.com Desc: types.go
Index ¶
- Variables
- type BroadcastArgs
- type Context
- func (c *Context) BindGate(uid int64) error
- func (c *Context) BindNode() error
- func (c *Context) Context() context.Context
- func (c *Context) Disconnect(isForce ...bool) error
- func (c *Context) GetIP() (string, error)
- func (c *Context) GetNodeId() string
- func (c *Context) Response(message interface{}) error
- func (c *Context) UnbindGate() error
- func (c *Context) UnbindNode() error
- type DeliverArgs
- type DeliverArgs2
- type DisconnectArgs
- type Event
- type EventHandler
- type Events
- type GateGrpcClient
- func (c *GateGrpcClient) Bind(ctx context.Context, cid, uid int64) (miss bool, err error)
- func (c *GateGrpcClient) Broadcast(ctx context.Context, kind session.Kind, message *packet.Message) (int64, error)
- func (c *GateGrpcClient) Disconnect(ctx context.Context, kind session.Kind, target int64, isForce bool) (miss bool, err error)
- func (c *GateGrpcClient) GetIP(ctx context.Context, kind session.Kind, target int64) (ip string, miss bool, err error)
- func (c *GateGrpcClient) Multicast(ctx context.Context, kind session.Kind, targets []int64, ...) (int64, error)
- func (c *GateGrpcClient) Push(ctx context.Context, kind session.Kind, target int64, message *packet.Message) (miss bool, err error)
- func (c *GateGrpcClient) Stat(ctx context.Context, kind session.Kind) (int64, error)
- func (c *GateGrpcClient) Unbind(ctx context.Context, uid int64) (miss bool, err error)
- type GetIPArgs
- type Message
- type Middleware
- type MiddlewareHandler
- type MulticastArgs
- type Node
- type NodeGrpcClient
- type Option
- func WithCodec(codec encoding.Codec) Option
- func WithContext(ctx context.Context) Option
- func WithID(id string) Option
- func WithLocator(locator locate.Locator) Option
- func WithName(name string) Option
- func WithRegistry(r registry.Registry) Option
- func WithTimeout(timeout time.Duration) Option
- func WithTransporter(transporter *Transport) Option
- func WithWeight(weight int) Option
- type Proxy
- func (p *Proxy) AskGate(ctx context.Context, uid int64, gid string) (string, bool, error)
- func (p *Proxy) AskNode(ctx context.Context, uid int64, nid string) (string, bool, error)
- func (p *Proxy) BindGate(ctx context.Context, uid int64, gid string, cid int64) error
- func (p *Proxy) BindNode(ctx context.Context, uid int64, nid ...string) error
- func (p *Proxy) Broadcast(ctx context.Context, args *BroadcastArgs) (int64, error)
- func (p *Proxy) Deliver(ctx context.Context, args *DeliverArgs) error
- func (p *Proxy) Deliver2(ctx context.Context, args *DeliverArgs2) error
- func (p *Proxy) Disconnect(ctx context.Context, args *DisconnectArgs) error
- func (p *Proxy) Events() *Events
- func (p *Proxy) FetchGateList(ctx context.Context, states ...int32) ([]*registry.ServiceInstance, error)
- func (p *Proxy) FetchNodeIdListByRoute(ctx context.Context, routeIds ...int32) ([]string, error)
- func (p *Proxy) FetchNodeList(ctx context.Context, states ...int32) ([]*registry.ServiceInstance, error)
- func (p *Proxy) FetchServiceList(ctx context.Context, kind string, states ...int32) ([]*registry.ServiceInstance, error)
- func (p *Proxy) GetIP(ctx context.Context, args *GetIPArgs) (string, error)
- func (p *Proxy) GetNodeID() string
- func (p *Proxy) GetNodeName() string
- func (p *Proxy) GetNodeState() int32
- func (p *Proxy) LocateGate(ctx context.Context, uid int64) (string, error)
- func (p *Proxy) LocateNode(ctx context.Context, uid int64) (string, error)
- func (p *Proxy) Multicast(ctx context.Context, args *MulticastArgs) (int64, error)
- func (p *Proxy) Push(ctx context.Context, args *PushArgs) error
- func (p *Proxy) Response(ctx context.Context, req *Request, data interface{}) error
- func (p *Proxy) Router() *Router
- func (p *Proxy) SetNodeState(state int32)
- func (p *Proxy) UnbindGate(ctx context.Context, uid int64) error
- func (p *Proxy) UnbindNode(ctx context.Context, uid int64, nid ...string) error
- func (p *Proxy) WatchServiceInstance(ctx context.Context, kinds ...string)
- type PushArgs
- type Request
- type RouteHandler
- type Router
- func (r *Router) AddRouteHandler(route int32, stateful bool, handler RouteHandler, ...)
- func (r *Router) CheckRouteStateful(route int32) (stateful bool, exist bool)
- func (r *Router) Group(groups ...func(group *RouterGroup)) *RouterGroup
- func (r *Router) HasDefaultRouteHandler() bool
- func (r *Router) SetDefaultRouteHandler(handler RouteHandler)
- type RouterGroup
- type ServerOptions
- type TransOptionFunc
- type Transport
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidArgument = errors.New("ErrInvalidArgument") ErrNotFoundUserSource = errors.New("not found user source") ErrInvalidGID = errors.New("invalid gate id") ErrInvalidSessionKind = errors.New("invalid session kind") ErrInvalidMessage = errors.New("invalid message") ErrInvalidNID = errors.New("invalid node id") ErrReceiveTargetEmpty = errors.New("the receive target is empty") )
Functions ¶
This section is empty.
Types ¶
type BroadcastArgs ¶
type Context ¶
type Context struct { Proxy *Proxy Request *Request Middleware *Middleware // contains filtered or unexported fields }
func (*Context) Disconnect ¶
Disconnect 关闭来自网关的连接
type DeliverArgs ¶
type DeliverArgs2 ¶
type DisconnectArgs ¶
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 int32, handler EventHandler)
AddEventHandler 添加事件处理器
type GateGrpcClient ¶
type GateGrpcClient struct {
// contains filtered or unexported fields
}
func NewGateClient ¶
func NewGateClient(cc *grpc.ClientConn) *GateGrpcClient
func (*GateGrpcClient) Broadcast ¶
func (c *GateGrpcClient) Broadcast(ctx context.Context, kind session.Kind, message *packet.Message) (int64, error)
Broadcast 推送广播消息
func (*GateGrpcClient) Disconnect ¶
func (c *GateGrpcClient) Disconnect(ctx context.Context, kind session.Kind, target int64, isForce bool) (miss bool, err error)
Disconnect 断开连接
func (*GateGrpcClient) GetIP ¶
func (c *GateGrpcClient) GetIP(ctx context.Context, kind session.Kind, target int64) (ip string, miss bool, err error)
GetIP 获取客户端IP
func (*GateGrpcClient) Multicast ¶
func (c *GateGrpcClient) Multicast(ctx context.Context, kind session.Kind, targets []int64, message *packet.Message) (int64, error)
Multicast 推送组播消息
func (*GateGrpcClient) Push ¶
func (c *GateGrpcClient) Push(ctx context.Context, kind session.Kind, target int64, message *packet.Message) (miss bool, err error)
Push 推送消息
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
type MiddlewareHandler ¶
type MiddlewareHandler func(ctx *Context)
type MulticastArgs ¶
type NodeGrpcClient ¶
type NodeGrpcClient struct {
// contains filtered or unexported fields
}
func NewNodeClient ¶
func NewNodeClient(cc *grpc.ClientConn) *NodeGrpcClient
func (*NodeGrpcClient) Deliver ¶
func (c *NodeGrpcClient) Deliver(ctx context.Context, args *cluster.DeliverArgs) (miss bool, err error)
Deliver 投递消息
func (*NodeGrpcClient) Trigger ¶
func (c *NodeGrpcClient) Trigger(ctx context.Context, args *cluster.TriggerArgs) (miss bool, err error)
Trigger 触发事件
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
func (*Proxy) BindNode ¶
BindNode 绑定节点 单个用户只能被绑定到某一台节点服务器上,多次绑定会直接覆盖上次绑定 绑定操作会通过发布订阅方式同步到网关服务器和其他相关节点服务器上 NID 为需要绑定的节点ID,默认绑定到当前节点上
func (*Proxy) Deliver ¶
func (p *Proxy) Deliver(ctx context.Context, args *DeliverArgs) error
Deliver投递消息给节点处理
func (*Proxy) Deliver2 ¶
func (p *Proxy) Deliver2(ctx context.Context, args *DeliverArgs2) error
Deliver 投递消息给节点处理
func (*Proxy) Disconnect ¶
func (p *Proxy) Disconnect(ctx context.Context, args *DisconnectArgs) error
Disconnect 断开连接
func (*Proxy) FetchGateList ¶
func (p *Proxy) FetchGateList(ctx context.Context, states ...int32) ([]*registry.ServiceInstance, error)
FetchGateList 拉取网关列表
func (*Proxy) FetchNodeIdListByRoute ¶
获得路由相关的node列表
func (*Proxy) FetchNodeList ¶
func (p *Proxy) FetchNodeList(ctx context.Context, states ...int32) ([]*registry.ServiceInstance, error)
FetchNodeList 拉取节点列表
func (*Proxy) FetchServiceList ¶
func (p *Proxy) FetchServiceList(ctx context.Context, kind string, states ...int32) ([]*registry.ServiceInstance, error)
FetchServiceList 拉取服务列表
func (*Proxy) LocateGate ¶
LocateGate 定位用户所在网关
func (*Proxy) LocateNode ¶
LocateNode 定位用户所在节点
func (*Proxy) UnbindGate ¶
UnbindGate 解绑网关
func (*Proxy) UnbindNode ¶
UnbindNode 解绑节点 解绑时会对解绑节点ID进行校验,不匹配则解绑失败 解绑操作会通过发布订阅方式同步到网关服务器和其他相关节点服务器上 NID 为需要解绑的节点ID,默认解绑当前节点
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 请求数据
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 ¶
CheckRouteStateful 是否为有状态路由
func (*Router) Group ¶
func (r *Router) Group(groups ...func(group *RouterGroup)) *RouterGroup
Group 路由组
func (*Router) HasDefaultRouteHandler ¶
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 添加中间件
type ServerOptions ¶
type ServerOptions struct { Addr string ServerOpts []mygrpc.ServerOption }
type TransOptionFunc ¶
type TransOptionFunc func(o *transOptions)
func WithClientDialOptions ¶
func WithClientDialOptions(opts ...grpc.DialOption) TransOptionFunc
WithClientDialOptions 设置客户端拨号选项
func WithClientPoolSize ¶
func WithClientPoolSize(size int) TransOptionFunc
WithClientPoolSize 设置客户端连接池大小
func WithServerListenAddr ¶
func WithServerListenAddr(addr string) TransOptionFunc
WithServerListenAddr 设置服务器监听地址
func WithServerOptions ¶
func WithServerOptions(opts ...mygrpc.ServerOption) TransOptionFunc
WithServerOptions 设置服务器选项
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
func NewTransport ¶
func NewTransport(opts ...TransOptionFunc) *Transport
func (*Transport) NewGateClient ¶
func (t *Transport) NewGateClient(ep *endpoint.Endpoint) (*GateGrpcClient, error)
NewGateClient 新建网关客户端
func (*Transport) NewNodeClient ¶
func (t *Transport) NewNodeClient(ep *endpoint.Endpoint) (*NodeGrpcClient, error)