From 5aeff7c786c7cacde5e1b3e42e58aacca6f1e8d8 Mon Sep 17 00:00:00 2001 From: "DESKTOP-V763RJ7\\Administrator" <835606593@qq.com> Date: Mon, 19 Jan 2026 10:53:12 +0800 Subject: [PATCH] =?UTF-8?q?feat=20grpc=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/app.go | 3 ++- app/grpc.go | 32 ----------------------------- internal/grpc_server/server_init.go | 5 +++-- 3 files changed, 5 insertions(+), 35 deletions(-) delete mode 100644 app/grpc.go diff --git a/app/app.go b/app/app.go index 0b45d4e..4b432cc 100644 --- a/app/app.go +++ b/app/app.go @@ -6,6 +6,7 @@ import ( "git.hlsq.asia/mmorpg/service-common/log" "git.hlsq.asia/mmorpg/service-common/module" "git.hlsq.asia/mmorpg/service-gateway/config" + "git.hlsq.asia/mmorpg/service-gateway/internal/grpc_server" "github.com/judwhite/go-svc" ) @@ -22,7 +23,7 @@ func (p *Program) Init(_ svc.Environment) error { p.moduleList = append(p.moduleList, (&module.DB{}).Bind(config.Get().DB)) p.moduleList = append(p.moduleList, &ModuleWebServer{}) p.moduleList = append(p.moduleList, &ModuleWebsocketServer{}) - p.moduleList = append(p.moduleList, &ModuleGrpcServer{}) + p.moduleList = append(p.moduleList, (&module.Grpc{}).Bind(grpc_server.NewServer(config.Get().Serve.Grpc))) p.moduleList = append(p.moduleList, &ModuleLoginQueue{}) p.moduleList = append(p.moduleList, (&module.Prometheus{}).Bind(config.Get().Metric)) p.moduleList = append(p.moduleList, (&module.Tracer{}).Bind(config.Get().Metric, common.KeyDiscoverServiceNameGateway)) diff --git a/app/grpc.go b/app/grpc.go deleted file mode 100644 index f463e64..0000000 --- a/app/grpc.go +++ /dev/null @@ -1,32 +0,0 @@ -package app - -import ( - "git.hlsq.asia/mmorpg/service-common/module" - "git.hlsq.asia/mmorpg/service-common/net/grpc/service" - "git.hlsq.asia/mmorpg/service-gateway/config" - "git.hlsq.asia/mmorpg/service-gateway/internal/grpc_server" -) - -// ModuleGrpcServer Grpc服务模块 -type ModuleGrpcServer struct { - server service.IService -} - -func (m *ModuleGrpcServer) Init() error { - return nil -} - -func (m *ModuleGrpcServer) Start() error { - m.server = grpc_server.NewServer(config.Get().Serve.Grpc.TTL) - m.server.Init(config.Get().Serve.Grpc.Address, config.Get().Serve.Grpc.Port) - return nil -} - -func (m *ModuleGrpcServer) Stop() error { - m.server.Close() - return nil -} - -func (m *ModuleGrpcServer) Bind(_ ...any) module.Module { - return m -} diff --git a/internal/grpc_server/server_init.go b/internal/grpc_server/server_init.go index eaac01b..3ed5d18 100644 --- a/internal/grpc_server/server_init.go +++ b/internal/grpc_server/server_init.go @@ -1,6 +1,7 @@ package grpc_server import ( + "git.hlsq.asia/mmorpg/service-common/config" "git.hlsq.asia/mmorpg/service-common/discover/common" "git.hlsq.asia/mmorpg/service-common/net/grpc/service" "git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb" @@ -13,12 +14,12 @@ type Server struct { service.Base } -func NewServer(ttl int64) *Server { +func NewServer(cfg *config.GrpcConfig) *Server { s := &Server{ Base: service.Base{ Target: common.KeyDiscoverGateway, ServiceName: common.KeyDiscoverServiceNameGateway, - EtcdTTL: ttl, + Cfg: cfg, }, } s.Base.OnCustomGrpcServerOption = s.OnCustomGrpcServerOption