Documentation ¶
Index ¶
- func Broadcast(ctx context.Context, srv, uid string, cmd int32, req codec.Codec, ...) (err error)
- func Event(ctx context.Context, srv, route, uid string, cmd int32, event codec.Codec, ...) (err error)
- func GetDiscorey() registry.Discovery
- func MustGetGrpcAddrsByName(ctx context.Context, srvName string) []string
- func Notify(ctx context.Context, target string, uid string, cmd int32, req codec.Codec, ...) (err error)
- func NotifyAll(ctx context.Context, srv string, cmd int32, req codec.Codec, ...) (err error)
- func Request(ctx context.Context, srv, route, uid string, cmd int32, req, rsp codec.Codec, ...) (err error)
- func SetDefaultClient(cli Client)
- func SetDiscorey(dis registry.Discovery)
- type CallInfo
- type CallOption
- type Client
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Broadcast ¶
func Broadcast(ctx context.Context, srv, uid string, cmd int32, req codec.Codec, opts ...CallOption) (err error)
Broadcast 将 req 广播到所有的srv服务上
func Event ¶
func Event(ctx context.Context, srv, route, uid string, cmd int32, event codec.Codec, opts ...CallOption) (err error)
Request 发送 event 到target服务, srv为服务名
func GetDiscorey ¶
func MustGetGrpcAddrsByName ¶
func Notify ¶
func Notify(ctx context.Context, target string, uid string, cmd int32, req codec.Codec, opts ...CallOption) (err error)
Notify 对某几个玩家发送通知
func NotifyAll ¶
func NotifyAll(ctx context.Context, srv string, cmd int32, req codec.Codec, opts ...CallOption) (err error)
NotifyAll 对所有在线玩家发送通知
func Request ¶
func Request(ctx context.Context, srv, route, uid string, cmd int32, req, rsp codec.Codec, opts ...CallOption) (err error)
Request 发送 req 到target服务, srv为服务名,如果要发送到特定地址的服务,需要带上 WithAddr(addr)这个CallOption
func SetDefaultClient ¶
func SetDefaultClient(cli Client)
func SetDiscorey ¶
Types ¶
type CallInfo ¶
type CallInfo struct { Target string //必填,目标服务名,当Addr不为空时,请求根据一致性hash发送到某个服务 UID string //必填,表示发送消息的玩家id,可以为空 Route string //必填,用于一致性hash路由,可以为空 Cmd int32 //必填,请求命令字 Req codec.Codec //必填,请求数据 Rsp codec.Codec //选填,回包 Addr string //选填,服务地址,当该地址不为空的时候,请求发送到该地址所在的服务, 其地址格式类似:grpc://127.0.0.1:32521 Type message.Type }
type CallOption ¶
type CallOption func(o *CallInfo)
func WithAddr ¶
func WithAddr(addr string) CallOption
type Client ¶
type Client interface { // Request 发送 req 到target服务, srv为服务名, 如果要发送到特定地址的服务,需要带上 WithAddr(addr)这个CallOption Request(ctx context.Context, srv, route, uid string, cmd int32, req, rsp codec.Codec, opts ...CallOption) (err error) // Request 发送 event 到target服务, srv为服务名 Event(ctx context.Context, srv, route, uid string, cmd int32, event codec.Codec, opts ...CallOption) (err error) // Broadcast 将 req 广播到所有的srv服务上 Broadcast(ctx context.Context, srv, uid string, cmd int32, req codec.Codec, opts ...CallOption) (err error) //Notify 对某几个玩家发送通知 Notify(ctx context.Context, srv string, uid string, cmd int32, req codec.Codec, opts ...CallOption) (err error) //NotifyAll 对所有在线玩家发送通知 NotifyAll(ctx context.Context, srv string, cmd int32, req codec.Codec, opts ...CallOption) (err error) }
Click to show internal directories.
Click to hide internal directories.