feat grpc模块

This commit is contained in:
2026-01-19 10:53:15 +08:00
parent ee5a840048
commit 5b20da3af1
3 changed files with 5 additions and 35 deletions

View File

@@ -6,6 +6,7 @@ import (
"git.hlsq.asia/mmorpg/service-common/log"
"git.hlsq.asia/mmorpg/service-common/module"
"git.hlsq.asia/mmorpg/service-scene/config"
"git.hlsq.asia/mmorpg/service-scene/internal/grpc_server"
"github.com/judwhite/go-svc"
)
@@ -20,7 +21,7 @@ func (p *Program) Init(_ svc.Environment) error {
}
p.moduleList = append(p.moduleList, base)
p.moduleList = append(p.moduleList, (&module.DB{}).Bind(config.Get().DB))
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, (&module.Prometheus{}).Bind(config.Get().Metric))
p.moduleList = append(p.moduleList, (&module.Tracer{}).Bind(config.Get().Metric, common.KeyDiscoverServiceNameScene))
p.moduleList = append(p.moduleList, &module.Discover{})

View File

@@ -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-scene/config"
"git.hlsq.asia/mmorpg/service-scene/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
}

View File

@@ -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"
@@ -12,12 +13,12 @@ type Server struct {
service.Base
}
func NewServer(ttl int64) *Server {
func NewServer(cfg *config.GrpcConfig) *Server {
s := &Server{
Base: service.Base{
Target: common.KeyDiscoverScene,
ServiceName: common.KeyDiscoverServiceNameScene,
EtcdTTL: ttl,
Cfg: cfg,
},
}
s.Base.OnCustomGrpcServerOption = s.OnCustomGrpcServerOption