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/log"
|
||||||
"git.hlsq.asia/mmorpg/service-common/module"
|
"git.hlsq.asia/mmorpg/service-common/module"
|
||||||
"git.hlsq.asia/mmorpg/service-scene/config"
|
"git.hlsq.asia/mmorpg/service-scene/config"
|
||||||
|
"git.hlsq.asia/mmorpg/service-scene/internal/grpc_server"
|
||||||
"github.com/judwhite/go-svc"
|
"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, base)
|
||||||
p.moduleList = append(p.moduleList, (&module.DB{}).Bind(config.Get().DB))
|
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.Prometheus{}).Bind(config.Get().Metric))
|
||||||
p.moduleList = append(p.moduleList, (&module.Tracer{}).Bind(config.Get().Metric, common.KeyDiscoverServiceNameScene))
|
p.moduleList = append(p.moduleList, (&module.Tracer{}).Bind(config.Get().Metric, common.KeyDiscoverServiceNameScene))
|
||||||
p.moduleList = append(p.moduleList, &module.Discover{})
|
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-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
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package grpc_server
|
package grpc_server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.hlsq.asia/mmorpg/service-common/config"
|
||||||
"git.hlsq.asia/mmorpg/service-common/discover/common"
|
"git.hlsq.asia/mmorpg/service-common/discover/common"
|
||||||
"git.hlsq.asia/mmorpg/service-common/net/grpc/service"
|
"git.hlsq.asia/mmorpg/service-common/net/grpc/service"
|
||||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
||||||
@@ -12,12 +13,12 @@ type Server struct {
|
|||||||
service.Base
|
service.Base
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(ttl int64) *Server {
|
func NewServer(cfg *config.GrpcConfig) *Server {
|
||||||
s := &Server{
|
s := &Server{
|
||||||
Base: service.Base{
|
Base: service.Base{
|
||||||
Target: common.KeyDiscoverScene,
|
Target: common.KeyDiscoverScene,
|
||||||
ServiceName: common.KeyDiscoverServiceNameScene,
|
ServiceName: common.KeyDiscoverServiceNameScene,
|
||||||
EtcdTTL: ttl,
|
Cfg: cfg,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
s.Base.OnCustomGrpcServerOption = s.OnCustomGrpcServerOption
|
s.Base.OnCustomGrpcServerOption = s.OnCustomGrpcServerOption
|
||||||
|
|||||||
Reference in New Issue
Block a user