Compare commits

...

3 Commits

5 changed files with 14 additions and 43 deletions

View File

@@ -16,21 +16,15 @@ type Program struct {
} }
func (p *Program) Init(_ svc.Environment) error { func (p *Program) Init(_ svc.Environment) error {
base := &ModuleBase{} p.moduleList = append(p.moduleList, &module.Log{Cfg: config.Get().Log})
if err := base.Init(); err != nil { p.moduleList = append(p.moduleList, &module.DB{Cfg: config.Get().DB, AppName: config.Get().App.Name})
return err p.moduleList = append(p.moduleList, &module.Snowflake{})
} p.moduleList = append(p.moduleList, &module.Grpc{Server: grpc_server.NewServer(config.Get().Serve.Grpc)})
p.moduleList = append(p.moduleList, base) p.moduleList = append(p.moduleList, &module.Prometheus{Cfg: config.Get().Metric})
p.moduleList = append(p.moduleList, (&module.DB{}).Bind(config.Get().DB, config.Get().App.Name)) p.moduleList = append(p.moduleList, &module.Tracer{Cfg: config.Get().Metric, ServiceName: common.KeyDiscoverServiceNameUser})
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.KeyDiscoverServiceNameUser))
p.moduleList = append(p.moduleList, &module.Discover{}) p.moduleList = append(p.moduleList, &module.Discover{})
for i, m := range p.moduleList { for _, m := range p.moduleList {
if i == 0 {
continue
}
if err := m.Init(); err != nil { if err := m.Init(); err != nil {
return err return err
} }

View File

@@ -1,27 +0,0 @@
package app
import (
"git.hlsq.asia/mmorpg/service-common/log"
"git.hlsq.asia/mmorpg/service-common/module"
"git.hlsq.asia/mmorpg/service-common/utils"
"git.hlsq.asia/mmorpg/service-user/config"
"math/rand"
)
// ModuleBase 基础模块,或者一些零散的模块
type ModuleBase struct {
module.DefaultModule
}
func (m *ModuleBase) Init() error {
// 配置
if err := config.LoadConfig(); err != nil {
return err
}
cfg := config.Get()
// 日志
log.Init(cfg.Log.Debug, cfg.Log.MaxSize, cfg.Log.MaxBackups, cfg.Log.MaxAge, cfg.Log.Level)
// 雪花
utils.InitSnowflake(int64(rand.Intn(1000)))
return nil
}

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-20260130035320-5dc5391b07ed git.hlsq.asia/mmorpg/service-common v0.0.0-20260207051302-0ca8a0ccbb14
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-20260130035320-5dc5391b07ed h1:O08p0egfekFqQSnc4sfEJUTI5dGiEyiDRNW/VYa/Ce4= git.hlsq.asia/mmorpg/service-common v0.0.0-20260207051302-0ca8a0ccbb14 h1:4r3tNWRzGVY3Xx6UiGjJJnwoMoWlVqbyGrljxl5d/nQ=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260130035320-5dc5391b07ed/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I= git.hlsq.asia/mmorpg/service-common v0.0.0-20260207051302-0ca8a0ccbb14/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I=
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/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE= github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE=

View File

@@ -3,11 +3,15 @@ package main
import ( import (
"fmt" "fmt"
"git.hlsq.asia/mmorpg/service-user/app" "git.hlsq.asia/mmorpg/service-user/app"
"git.hlsq.asia/mmorpg/service-user/config"
"github.com/judwhite/go-svc" "github.com/judwhite/go-svc"
"syscall" "syscall"
) )
func main() { func main() {
if err := config.LoadConfig(); err != nil {
fmt.Println(err)
}
if err := svc.Run(&app.Program{}, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL); err != nil { if err := svc.Run(&app.Program{}, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL); err != nil {
fmt.Println(err) fmt.Println(err)
} }