mirror of
https://github.com/zhufuyi/sponge.git
synced 2025-10-05 08:46:57 +08:00
optimised code
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/zhufuyi/sponge/internal/config"
|
||||
"github.com/zhufuyi/sponge/internal/model"
|
||||
|
||||
"github.com/zhufuyi/sponge/pkg/conf"
|
||||
"github.com/zhufuyi/sponge/pkg/logger"
|
||||
"github.com/zhufuyi/sponge/pkg/nacoscli"
|
||||
"github.com/zhufuyi/sponge/pkg/stat"
|
||||
@@ -26,8 +27,8 @@ var (
|
||||
enableConfigCenter bool
|
||||
)
|
||||
|
||||
// Config initial app configuration
|
||||
func Config() {
|
||||
// InitApp initial app configuration
|
||||
func InitApp() {
|
||||
initConfig()
|
||||
cfg := config.Get()
|
||||
|
||||
@@ -40,9 +41,12 @@ func Config() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
logger.Debug(config.Show())
|
||||
logger.Info("init logger succeeded")
|
||||
|
||||
// initializing database
|
||||
model.InitMysql()
|
||||
logger.Info("init mysql succeeded")
|
||||
model.InitCache(cfg.App.CacheType)
|
||||
|
||||
// initializing tracing
|
||||
@@ -55,6 +59,7 @@ func Config() {
|
||||
strconv.Itoa(cfg.Jaeger.AgentPort),
|
||||
cfg.App.TracingSamplingRate,
|
||||
)
|
||||
logger.Info("init tracer succeeded")
|
||||
}
|
||||
|
||||
// initializing the print system and process resources
|
||||
@@ -63,6 +68,7 @@ func Config() {
|
||||
stat.WithLog(logger.Get()),
|
||||
stat.WithAlarm(), // invalid if it is windows, the default threshold for cpu and memory is 0.8, you can modify them
|
||||
)
|
||||
logger.Info("init statistics succeeded")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,10 +92,14 @@ func initConfig() {
|
||||
appConfig := &config.Config{}
|
||||
params := &nacoscli.Params{}
|
||||
_ = copier.Copy(params, &nacosConfig.Nacos)
|
||||
err = nacoscli.Init(appConfig, params)
|
||||
format, data, err := nacoscli.GetConfig(params)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("connect to configuration center err, %v", err))
|
||||
}
|
||||
err = conf.ParseConfigData(data, format, appConfig)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("parse configuration data err, %v", err))
|
||||
}
|
||||
if appConfig.App.Name == "" {
|
||||
panic("read the config from center error, config data is empty")
|
||||
}
|
||||
@@ -108,5 +118,4 @@ func initConfig() {
|
||||
if version != "" {
|
||||
config.Get().App.Version = version
|
||||
}
|
||||
//fmt.Println(config.Show())
|
||||
}
|
||||
|
Reference in New Issue
Block a user