mirror of
https://github.com/zhufuyi/sponge.git
synced 2025-10-06 09:17:19 +08:00
optimised code
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
//"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"
|
||||
@@ -27,8 +28,8 @@ var (
|
||||
enableConfigCenter bool
|
||||
)
|
||||
|
||||
// Config initial app configuration
|
||||
func Config() {
|
||||
// InitApp initial app configuration
|
||||
func InitApp() {
|
||||
initConfig()
|
||||
cfg := config.Get()
|
||||
|
||||
@@ -41,9 +42,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
|
||||
@@ -56,6 +60,7 @@ func Config() {
|
||||
strconv.Itoa(cfg.Jaeger.AgentPort),
|
||||
cfg.App.TracingSamplingRate,
|
||||
)
|
||||
logger.Info("init tracer succeeded")
|
||||
}
|
||||
|
||||
// initializing the print system and process resources
|
||||
@@ -64,6 +69,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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,10 +93,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")
|
||||
}
|
||||
@@ -109,5 +119,4 @@ func initConfig() {
|
||||
if version != "" {
|
||||
config.Get().App.Version = version
|
||||
}
|
||||
//fmt.Println(config.Show())
|
||||
}
|
||||
|
Reference in New Issue
Block a user