Compare commits
2 Commits
ee5a840048
...
cb37409593
| Author | SHA1 | Date | |
|---|---|---|---|
| cb37409593 | |||
| 5b20da3af1 |
14
app/app.go
14
app/app.go
@@ -6,7 +6,9 @@ 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"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Program struct {
|
||||
@@ -20,7 +22,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{})
|
||||
@@ -38,8 +40,16 @@ func (p *Program) Init(_ svc.Environment) error {
|
||||
}
|
||||
|
||||
func (p *Program) Start() error {
|
||||
ready := &sync.WaitGroup{}
|
||||
ready.Add(len(p.moduleList))
|
||||
for _, m := range p.moduleList {
|
||||
if err := m.Start(); err != nil {
|
||||
if err := m.Start(ready); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
ready.Wait()
|
||||
for _, m := range p.moduleList {
|
||||
if err := m.AfterStart(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
13
app/base.go
13
app/base.go
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
// ModuleBase 基础模块,或者一些零散的模块
|
||||
type ModuleBase struct {
|
||||
module.DefaultModule
|
||||
}
|
||||
|
||||
func (m *ModuleBase) Init() error {
|
||||
@@ -24,15 +25,3 @@ func (m *ModuleBase) Init() error {
|
||||
utils.InitSnowflake(int64(rand.Intn(1000)))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ModuleBase) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ModuleBase) Stop() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ModuleBase) Bind(_ ...any) module.Module {
|
||||
return m
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-scene
|
||||
go 1.24.0
|
||||
|
||||
require (
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260117160658-22d48542a852
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260120040718-1edebb439c58
|
||||
github.com/judwhite/go-svc v1.2.1
|
||||
go.uber.org/zap v1.27.0
|
||||
google.golang.org/grpc v1.77.0
|
||||
|
||||
4
go.sum
4
go.sum
@@ -1,7 +1,7 @@
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260117160658-22d48542a852 h1:ehZ54MgGL3CO7KKDPxybFabIXxiQud1TGMcKjrSTcnw=
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260117160658-22d48542a852/go.mod h1:Dazg+4woCv9Jk7jgT2qUSGWhZOXx/0WYfJO+FCUDyhw=
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260120040718-1edebb439c58 h1:Bgn3rrISGqzyNA4ax5o4tiTy3tK3QcM/+tCr80fOBhE=
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260120040718-1edebb439c58/go.mod h1:Dazg+4woCv9Jk7jgT2qUSGWhZOXx/0WYfJO+FCUDyhw=
|
||||
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
||||
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user