Documentation ¶
Overview ¶
Package rpc @Description: rpc的封装,使用了rpcx框架 @Link: https://doc.rpcx.io/part4/alias.html rpcx框架 @Ref:
Index ¶
- Variables
- func BorderAllServiceRPCMessageByContext[Req any, Res any](ct context.Context, api *ServiceAPI[Req, Res])
- func BorderRPCMessage[Req any, Res any](ct context.Context, api *ServiceAPI[Req, Res])
- func GetNodeId(ctx context.Context) string
- func GetTemplateUserId(ctx context.Context) string
- func GetUserId(ctx context.Context) string
- func NewBindRPCContext(userId ...string) context.Context
- func NewCacheUserContext(userId string) context.Context
- func NewCustomSelector(moduleName string) client2.Selector
- func NewRPCContext() context.Context
- func NewRPCXClientHandler() client2.PostCallPlugin
- func NewUserRPCContext(userId string) context.Context
- func SendNoReplyRPCMessage[Req any, Res any](ct context.Context, api *ServiceAPI[Req, Res]) error
- func SendRPCMessage[Req any, Res any](ct context.Context, api *ServiceAPI[Req, Res]) (res Res, err error)
- func SendToGate(ct context.Context, messageType string, pbMessage proto.Message) error
- func SendToGateByUserId(userId, messageType string, pbMessage proto.Message) error
- type Args
- type Call
- type Client
- type ClientOptional
- type CustomSelector
- type DefaultArgs
- type DefaultBool
- type DefaultReply
- type EmptyReply
- type GateService
- func (g *GateService) GetName() string
- func (g *GateService) GetVersion() string
- func (g *GateService) Login(ctx context.Context, args *LoginReq, reply *LoginRes) error
- func (g *GateService) Offline(ctx context.Context, args *OfflineReq, reply *OfflineRes) error
- func (g *GateService) Startup() (bool, error)
- func (g *GateService) ToUser(ctx context.Context, args *ToUserReq, reply *ToUserRes) error
- func (g *GateService) UploadUserNodeInfo(ctx context.Context, args *UploadUserNodeInfoReq, reply *UploadUserNodeInfoRes) error
- type HeaderMessageType
- type ILoginCheck
- type IService
- type ITCPBuilder
- type ITCPService
- type IUserConnectData
- type IUserHook
- type LoginReq
- type LoginRes
- type Module
- type OfflineReq
- type OfflineRes
- type Optional
- type RPCXClientHandler
- type Reply
- type RequestData
- type RequestHeader
- type ResponseHeader
- type Server
- func (s *Server) Destroy()
- func (s *Server) Run() chan bool
- func (s *Server) WithCache(module tgf.CacheModule) *Server
- func (s *Server) WithCustomServiceAddress()
- func (s *Server) WithGameConfig(path string) *Server
- func (s *Server) WithGateway(port string, hook IUserHook) *Server
- func (s *Server) WithGatewayWS(port, path string, hook IUserHook) *Server
- func (s *Server) WithProfileDebug() *Server
- func (s *Server) WithRandomServicePort(minPort, maxPort int32) *Server
- func (s *Server) WithServerPool(maxWorkers, maxCapacity int) *Server
- func (s *Server) WithService(service IService) *Server
- func (s *Server) WithWhiteService(serviceName string) *Server
- type ServerConfig
- func (s *ServerConfig) Address() string
- func (s *ServerConfig) DeadLineTime() time.Duration
- func (s *ServerConfig) IsWebSocket() bool
- func (s *ServerConfig) MaxConnections() int32
- func (s *ServerConfig) Port() string
- func (s *ServerConfig) ReadBufferSize() int
- func (s *ServerConfig) SetUserHook(userHook IUserHook)
- func (s *ServerConfig) UserHook() IUserHook
- func (s *ServerConfig) WithBuffer(readBuffer, writeBuffer int) ITCPBuilder
- func (s *ServerConfig) WithPort(port string) ITCPBuilder
- func (s *ServerConfig) WithWSPath(path string) ITCPBuilder
- func (s *ServerConfig) WriteBufferSize() int
- func (s *ServerConfig) WsPath() string
- type ServiceAPI
- type TCPServer
- func (t *TCPServer) DoLogin(userId, templateUserId string) (err error)
- func (t *TCPServer) Offline(userId string, replace bool) (exists bool)
- func (t *TCPServer) Run()
- func (t *TCPServer) SetUserHook(userHook IUserHook)
- func (t *TCPServer) ToUser(userId, messageType string, data []byte)
- func (t *TCPServer) Update()
- func (t *TCPServer) UpdateUserNodeInfo(userId, servicePath, nodeId string) bool
- type ToUserReq
- type ToUserRes
- type UploadUserNodeInfoReq
- type UploadUserNodeInfoRes
- type UserConnectData
- func (u *UserConnectData) GetChannel() chan *client.Call
- func (u *UserConnectData) GetContextData() *share.Context
- func (u *UserConnectData) IsLogin() bool
- func (u *UserConnectData) Login(userId string)
- func (u *UserConnectData) Offline(userHook IUserHook)
- func (u *UserConnectData) Send(data []byte)
- func (u *UserConnectData) Stop()
- func (u *UserConnectData) UpdateUserNodeId(servicePath, nodeId string)
- type UserHook
- func (u *UserHook) AddLoginHook(hook *ServiceAPI[*DefaultArgs, *EmptyReply]) IUserHook
- func (u *UserHook) AddOfflineHook(hook *ServiceAPI[*DefaultArgs, *EmptyReply]) IUserHook
- func (u *UserHook) GetLoginHooks() []*ServiceAPI[*DefaultArgs, *EmptyReply]
- func (u *UserHook) GetOfflineHooks() []*ServiceAPI[*DefaultArgs, *EmptyReply]
- type WSMessage
- func (*WSMessage) Descriptor() ([]byte, []int)deprecated
- func (x *WSMessage) GetData() []byte
- func (x *WSMessage) GetModule() string
- func (x *WSMessage) GetReqId() int32
- func (x *WSMessage) GetServiceName() string
- func (*WSMessage) ProtoMessage()
- func (x *WSMessage) ProtoReflect() protoreflect.Message
- func (x *WSMessage) Reset()
- func (x *WSMessage) String() string
- type WSResponse
- func (*WSResponse) Descriptor() ([]byte, []int)deprecated
- func (x *WSResponse) GetCode() int32
- func (x *WSResponse) GetData() []byte
- func (x *WSResponse) GetMessageType() string
- func (x *WSResponse) GetReqId() int32
- func (*WSResponse) ProtoMessage()
- func (x *WSResponse) ProtoReflect() protoreflect.Message
- func (x *WSResponse) Reset()
- func (x *WSResponse) String() string
Constants ¶
This section is empty.
Variables ¶
var ( UploadUserNodeInfo = &ServiceAPI[*UploadUserNodeInfoReq, *UploadUserNodeInfoRes]{ ModuleName: Gate.Name, Name: "UploadUserNodeInfo", } ToUser = &ServiceAPI[*ToUserReq, *ToUserRes]{ ModuleName: Gate.Name, Name: "ToUser", } Login = &ServiceAPI[*LoginReq, *LoginRes]{ ModuleName: Gate.Name, Name: "Login", } Offline = &ServiceAPI[*OfflineReq, *OfflineRes]{ ModuleName: Gate.Name, Name: "Offline", } )
var File_Users_AUSA_Documents_IdeaProject_tgf_example_kit_proto_ws_proto protoreflect.FileDescriptor
var Gate = &Module{Name: "Gate", Version: "1.0"}
Functions ¶
func BorderAllServiceRPCMessageByContext ¶
func BorderAllServiceRPCMessageByContext[Req any, Res any](ct context.Context, api *ServiceAPI[Req, Res])
func BorderRPCMessage ¶
func BorderRPCMessage[Req any, Res any](ct context.Context, api *ServiceAPI[Req, Res])
BorderRPCMessage [Req any, Res any]
@Description: 推送消息到所有服务节点 @param ct @param api @param Res]
func GetTemplateUserId ¶
func NewBindRPCContext ¶
NewBindRPCContext @Description: instantiate rpc context with binding, all user binging same node id. @param userId @return context.Context
func NewCacheUserContext ¶
func NewCustomSelector ¶
func NewRPCContext ¶
func NewRPCXClientHandler ¶
func NewRPCXClientHandler() client2.PostCallPlugin
func NewUserRPCContext ¶
NewUserRPCContext @Description: instantiate rpc context with user id @param userId @return context.Context
func SendNoReplyRPCMessage ¶
SendNoReplyRPCMessage [Req any, Res any]
@Description: 发送无需等待返回的rpc消息 @param ct @param api @param Res @return error
func SendRPCMessage ¶
func SendRPCMessage[Req any, Res any](ct context.Context, api *ServiceAPI[Req, Res]) (res Res, err error)
SendRPCMessage [Req, Res any]
@Description: 远程rpc调用 @param ct @param api @param Res @return res @return err
func SendToGate ¶
SendToGate @Description: 发送消息到用户所在的网关 @param ct @param pbMessage @return error
Types ¶
type Args ¶
type Args[T protoiface.MessageV1] struct { ByteData []byte }
type Call ¶
type Call struct {
// contains filtered or unexported fields
}
func SendAsyncRPCMessage ¶
func SendAsyncRPCMessage[Req any, Res any](ct context.Context, api *ServiceAPI[Req, Res]) (*Call, error)
SendAsyncRPCMessage [Req, Res any] @Description: 异步rpc请求,使用该接口时,需要确保call中的chan被消费, 避免chan的泄露 @param ct @param api @return *client.Call @return error
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) AddWhiteService ¶
func (*Client) CheckWhiteList ¶
type ClientOptional ¶
type ClientOptional struct { }
type CustomSelector ¶
type CustomSelector struct {
// contains filtered or unexported fields
}
func (*CustomSelector) Select ¶
func (c *CustomSelector) Select(ctx context.Context, servicePath, serviceMethod string, args interface{}) (selected string)
func (*CustomSelector) UpdateServer ¶
func (c *CustomSelector) UpdateServer(servers map[string]string)
type DefaultArgs ¶
type DefaultArgs struct {
C string
}
type DefaultBool ¶
type DefaultBool struct {
C bool
}
type DefaultReply ¶
type DefaultReply struct {
C int32
}
type EmptyReply ¶
type EmptyReply struct { }
type GateService ¶
type GateService struct { Module // contains filtered or unexported fields }
GateService @Description: 默认网关
func (*GateService) GetName ¶
func (g *GateService) GetName() string
func (*GateService) GetVersion ¶
func (g *GateService) GetVersion() string
func (*GateService) Offline ¶
func (g *GateService) Offline(ctx context.Context, args *OfflineReq, reply *OfflineRes) error
func (*GateService) Startup ¶
func (g *GateService) Startup() (bool, error)
func (*GateService) UploadUserNodeInfo ¶
func (g *GateService) UploadUserNodeInfo(ctx context.Context, args *UploadUserNodeInfoReq, reply *UploadUserNodeInfoRes) error
type HeaderMessageType ¶
type HeaderMessageType byte
const ( Heartbeat HeaderMessageType = iota + 1 Logic ReplaceLogin )
type ILoginCheck ¶
type IService ¶
type IService interface { GetName() string GetVersion() string Startup() (bool, error) Destroy(sub IService) }
IService
@Description: 逻辑服务接口
func GatewayService ¶
func GatewayService(tcpBuilder ITCPBuilder) IService
type ITCPBuilder ¶
type ITCPBuilder interface { WithPort(port string) ITCPBuilder WithBuffer(readBuffer, writeBuffer int) ITCPBuilder WithWSPath(path string) ITCPBuilder Address() string Port() string WsPath() string MaxConnections() int32 DeadLineTime() time.Duration ReadBufferSize() int WriteBufferSize() int IsWebSocket() bool SetUserHook(userHook IUserHook) UserHook() IUserHook }
type ITCPService ¶
type IUserConnectData ¶
type IUserHook ¶
type IUserHook interface { GetLoginHooks() []*ServiceAPI[*DefaultArgs, *EmptyReply] GetOfflineHooks() []*ServiceAPI[*DefaultArgs, *EmptyReply] AddLoginHook(hook *ServiceAPI[*DefaultArgs, *EmptyReply]) IUserHook AddOfflineHook(hook *ServiceAPI[*DefaultArgs, *EmptyReply]) IUserHook }
func NewUserHook ¶
func NewUserHook() IUserHook
type OfflineReq ¶
type OfflineRes ¶
type OfflineRes struct {
ErrorCode int32
}
type RequestData ¶
type RequestData struct { User *UserConnectData RequestMethod string Module string Data []byte MessageType HeaderMessageType ReqId int32 }
type RequestHeader ¶
type RequestHeader []byte
RequestHeader [1][1][2][2][n][n] magic number|message type|request method name size|data size|method name|data
type ResponseHeader ¶
type ResponseHeader []byte
ResponseHeader [1][1][2][4][n][n] message type|compress|request method name size|data size|method name|data
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server @Description:
func NewRPCServer ¶
func NewRPCServer() *Server
func (*Server) WithCustomServiceAddress ¶
func (s *Server) WithCustomServiceAddress()
WithCustomServiceAddress @Description: 开启自定义地址注册,通过常量ServiceAddress注册绑定的ip @receiver this
func (*Server) WithGameConfig ¶
func (*Server) WithGatewayWS ¶
func (*Server) WithProfileDebug ¶
func (*Server) WithRandomServicePort ¶
func (*Server) WithServerPool ¶
func (*Server) WithService ¶
func (*Server) WithWhiteService ¶
type ServerConfig ¶
type ServerConfig struct {
// contains filtered or unexported fields
}
func (*ServerConfig) Address ¶
func (s *ServerConfig) Address() string
func (*ServerConfig) DeadLineTime ¶
func (s *ServerConfig) DeadLineTime() time.Duration
func (*ServerConfig) IsWebSocket ¶
func (s *ServerConfig) IsWebSocket() bool
func (*ServerConfig) MaxConnections ¶
func (s *ServerConfig) MaxConnections() int32
func (*ServerConfig) Port ¶
func (s *ServerConfig) Port() string
func (*ServerConfig) ReadBufferSize ¶
func (s *ServerConfig) ReadBufferSize() int
func (*ServerConfig) SetUserHook ¶
func (s *ServerConfig) SetUserHook(userHook IUserHook)
func (*ServerConfig) UserHook ¶
func (s *ServerConfig) UserHook() IUserHook
func (*ServerConfig) WithBuffer ¶
func (s *ServerConfig) WithBuffer(readBuffer, writeBuffer int) ITCPBuilder
func (*ServerConfig) WithPort ¶
func (s *ServerConfig) WithPort(port string) ITCPBuilder
func (*ServerConfig) WithWSPath ¶
func (s *ServerConfig) WithWSPath(path string) ITCPBuilder
func (*ServerConfig) WriteBufferSize ¶
func (s *ServerConfig) WriteBufferSize() int
func (*ServerConfig) WsPath ¶
func (s *ServerConfig) WsPath() string
type ServiceAPI ¶
type ServiceAPI[Req, Res any] struct { ModuleName string Name string MessageType string Des string // contains filtered or unexported fields }
func (*ServiceAPI[Req, Res]) GetResult ¶
func (s *ServiceAPI[Req, Res]) GetResult() Res
func (*ServiceAPI[Req, Res]) New ¶
func (s *ServiceAPI[Req, Res]) New(req Req, res Res) *ServiceAPI[Req, Res]
func (*ServiceAPI[Req, Res]) NewEmpty ¶
func (s *ServiceAPI[Req, Res]) NewEmpty() *ServiceAPI[Req, Res]
type TCPServer ¶
type TCPServer struct {
// contains filtered or unexported fields
}
func (*TCPServer) SetUserHook ¶
func (*TCPServer) UpdateUserNodeInfo ¶
type UploadUserNodeInfoReq ¶
type UploadUserNodeInfoRes ¶
type UploadUserNodeInfoRes struct {
ErrorCode int32
}
type UserConnectData ¶
type UserConnectData struct {
// contains filtered or unexported fields
}
func (*UserConnectData) GetChannel ¶
func (u *UserConnectData) GetChannel() chan *client.Call
func (*UserConnectData) GetContextData ¶
func (u *UserConnectData) GetContextData() *share.Context
func (*UserConnectData) IsLogin ¶
func (u *UserConnectData) IsLogin() bool
func (*UserConnectData) Login ¶
func (u *UserConnectData) Login(userId string)
func (*UserConnectData) Offline ¶
func (u *UserConnectData) Offline(userHook IUserHook)
func (*UserConnectData) Send ¶
func (u *UserConnectData) Send(data []byte)
func (*UserConnectData) Stop ¶
func (u *UserConnectData) Stop()
func (*UserConnectData) UpdateUserNodeId ¶
func (u *UserConnectData) UpdateUserNodeId(servicePath, nodeId string)
type UserHook ¶
type UserHook struct {
// contains filtered or unexported fields
}
func (*UserHook) AddLoginHook ¶
func (u *UserHook) AddLoginHook(hook *ServiceAPI[*DefaultArgs, *EmptyReply]) IUserHook
func (*UserHook) AddOfflineHook ¶
func (u *UserHook) AddOfflineHook(hook *ServiceAPI[*DefaultArgs, *EmptyReply]) IUserHook
func (*UserHook) GetLoginHooks ¶
func (u *UserHook) GetLoginHooks() []*ServiceAPI[*DefaultArgs, *EmptyReply]
func (*UserHook) GetOfflineHooks ¶
func (u *UserHook) GetOfflineHooks() []*ServiceAPI[*DefaultArgs, *EmptyReply]
type WSMessage ¶
type WSMessage struct { Module string `protobuf:"bytes,1,opt,name=module,proto3" json:"module,omitempty"` ServiceName string `protobuf:"bytes,2,opt,name=serviceName,proto3" json:"serviceName,omitempty"` Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` ReqId int32 `protobuf:"varint,4,opt,name=reqId,proto3" json:"reqId,omitempty"` // contains filtered or unexported fields }
func (*WSMessage) Descriptor
deprecated
func (*WSMessage) GetServiceName ¶
func (*WSMessage) ProtoMessage ¶
func (*WSMessage) ProtoMessage()
func (*WSMessage) ProtoReflect ¶
func (x *WSMessage) ProtoReflect() protoreflect.Message
type WSResponse ¶
type WSResponse struct { MessageType string `protobuf:"bytes,1,opt,name=messageType,proto3" json:"messageType,omitempty"` Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` ReqId int32 `protobuf:"varint,3,opt,name=reqId,proto3" json:"reqId,omitempty"` Code int32 `protobuf:"varint,4,opt,name=code,proto3" json:"code,omitempty"` // contains filtered or unexported fields }
func (*WSResponse) Descriptor
deprecated
func (*WSResponse) Descriptor() ([]byte, []int)
Deprecated: Use WSResponse.ProtoReflect.Descriptor instead.
func (*WSResponse) GetCode ¶
func (x *WSResponse) GetCode() int32
func (*WSResponse) GetData ¶
func (x *WSResponse) GetData() []byte
func (*WSResponse) GetMessageType ¶
func (x *WSResponse) GetMessageType() string
func (*WSResponse) GetReqId ¶
func (x *WSResponse) GetReqId() int32
func (*WSResponse) ProtoMessage ¶
func (*WSResponse) ProtoMessage()
func (*WSResponse) ProtoReflect ¶
func (x *WSResponse) ProtoReflect() protoreflect.Message
func (*WSResponse) Reset ¶
func (x *WSResponse) Reset()
func (*WSResponse) String ¶
func (x *WSResponse) String() string