feat grpc模块
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"git.hlsq.asia/mmorpg/service-common/log"
|
||||
"git.hlsq.asia/mmorpg/service-common/module"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/config"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/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.KeyDiscoverServiceNameQgdzs))
|
||||
p.moduleList = append(p.moduleList, &module.Discover{})
|
||||
|
||||
32
app/grpc.go
32
app/grpc.go
@@ -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-qgdzs/config"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/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
|
||||
}
|
||||
@@ -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.KeyDiscoverQgdzs,
|
||||
ServiceName: common.KeyDiscoverServiceNameQgdzs,
|
||||
EtcdTTL: ttl,
|
||||
Cfg: cfg,
|
||||
},
|
||||
}
|
||||
s.Base.OnCustomGrpcServerOption = s.OnCustomGrpcServerOption
|
||||
|
||||
Reference in New Issue
Block a user