feat 模块增加after start

This commit is contained in:
2026-01-20 12:11:29 +08:00
parent 81bae2992d
commit f1f8e162e0
4 changed files with 14 additions and 16 deletions

View File

@@ -8,6 +8,7 @@ import (
"git.hlsq.asia/mmorpg/service-user/config" "git.hlsq.asia/mmorpg/service-user/config"
"git.hlsq.asia/mmorpg/service-user/internal/grpc_server" "git.hlsq.asia/mmorpg/service-user/internal/grpc_server"
"github.com/judwhite/go-svc" "github.com/judwhite/go-svc"
"sync"
) )
type Program struct { type Program struct {
@@ -39,8 +40,16 @@ func (p *Program) Init(_ svc.Environment) error {
} }
func (p *Program) Start() error { func (p *Program) Start() error {
ready := &sync.WaitGroup{}
ready.Add(len(p.moduleList))
for _, m := range 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 return err
} }
} }

View File

@@ -10,6 +10,7 @@ import (
// ModuleBase 基础模块,或者一些零散的模块 // ModuleBase 基础模块,或者一些零散的模块
type ModuleBase struct { type ModuleBase struct {
module.DefaultModule
} }
func (m *ModuleBase) Init() error { func (m *ModuleBase) Init() error {
@@ -24,15 +25,3 @@ func (m *ModuleBase) Init() error {
utils.InitSnowflake(int64(rand.Intn(1000))) utils.InitSnowflake(int64(rand.Intn(1000)))
return nil 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
}

2
go.mod
View File

@@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-user
go 1.24.0 go 1.24.0
require ( 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 github.com/judwhite/go-svc v1.2.1
google.golang.org/grpc v1.77.0 google.golang.org/grpc v1.77.0
gorm.io/gen v0.3.27 gorm.io/gen v0.3.27

4
go.sum
View File

@@ -1,7 +1,7 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= 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-20260120040718-1edebb439c58 h1:Bgn3rrISGqzyNA4ax5o4tiTy3tK3QcM/+tCr80fOBhE=
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/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 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=