From f1f8e162e0a820bb4473281f5693bcf373069cdc Mon Sep 17 00:00:00 2001 From: "DESKTOP-V763RJ7\\Administrator" <835606593@qq.com> Date: Tue, 20 Jan 2026 12:11:29 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=A8=A1=E5=9D=97=E5=A2=9E=E5=8A=A0afte?= =?UTF-8?q?r=20start?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/app.go | 11 ++++++++++- app/base.go | 13 +------------ go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/app/app.go b/app/app.go index 447cbe1..2e5fe5f 100644 --- a/app/app.go +++ b/app/app.go @@ -8,6 +8,7 @@ import ( "git.hlsq.asia/mmorpg/service-user/config" "git.hlsq.asia/mmorpg/service-user/internal/grpc_server" "github.com/judwhite/go-svc" + "sync" ) type Program struct { @@ -39,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 } } diff --git a/app/base.go b/app/base.go index 3aa9d9b..c1fb2de 100644 --- a/app/base.go +++ b/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 -} diff --git a/go.mod b/go.mod index aa735e0..1ddba08 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-user 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 google.golang.org/grpc v1.77.0 gorm.io/gen v0.3.27 diff --git a/go.sum b/go.sum index 020862d..6765c9e 100644 --- a/go.sum +++ b/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=