mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 16:02:26 +08:00
feat:rpc gs增加gm接口
This commit is contained in:
23
gs/service/gm.go
Normal file
23
gs/service/gm.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"hk4e/gs/api"
|
||||
"hk4e/gs/game"
|
||||
)
|
||||
|
||||
var _ api.GMNATSRPCServer = (*GMService)(nil)
|
||||
|
||||
type GMService struct {
|
||||
g *game.GameManager
|
||||
}
|
||||
|
||||
func (s *GMService) Cmd(ctx context.Context, req *api.CmdRequest) (*api.CmdReply, error) {
|
||||
//TODO implement me
|
||||
fmt.Println("Cmd", req.FuncName, req.Param)
|
||||
return &api.CmdReply{
|
||||
Message: "TODO",
|
||||
}, nil
|
||||
}
|
||||
34
gs/service/service.go
Normal file
34
gs/service/service.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"hk4e/gs/api"
|
||||
|
||||
"github.com/byebyebruce/natsrpc"
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/nats-io/nats.go/encoders/protobuf"
|
||||
)
|
||||
|
||||
type Service struct{}
|
||||
|
||||
func NewService(conn *nats.Conn) (*Service, error) {
|
||||
enc, err := nats.NewEncodedConn(conn, protobuf.PROTOBUF_ENCODER)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
svr, err := natsrpc.NewServer(enc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
gs := &GMService{}
|
||||
_, err = api.RegisterGMNATSRPCServer(svr, gs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Service{}, nil
|
||||
}
|
||||
|
||||
// Close 关闭
|
||||
func (s *Service) Close() {
|
||||
// TODO
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user