diff --git a/main.go b/main.go index 9d89360..4e024c2 100644 --- a/main.go +++ b/main.go @@ -32,9 +32,9 @@ func Run() error { \____|__ /\___ >__/\_ \ |__| |____| \___ >__| |__|_| /__|___| (____ /____/ \/ \/ \/ \/ \/ \/ \/ ` + Version + "\n\n") - global.Config = config.SetupConfig() + // 为了兼容之前调用global包的代码 后期预期会改为调用pgk/config + global.Config = config.GlobalCfg - global.Store = global.NewStore() global.Cron = cron.New(cron.WithSeconds()) //精确到秒 global.Cron.Start() diff --git a/pkg/config/config.go b/pkg/config/config.go index 3640071..5fe0868 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -8,6 +8,8 @@ import ( "github.com/spf13/viper" ) +var GlobalCfg *Config + type Config struct { Debug bool Demo bool @@ -84,6 +86,10 @@ func SetupConfig() *Config { Debug: viper.GetBool("debug"), Demo: viper.GetBool("demo"), } - + GlobalCfg = config return config } + +func init() { + GlobalCfg = SetupConfig() +} diff --git a/pkg/global/global.go b/pkg/global/global.go index b685078..77019f4 100644 --- a/pkg/global/global.go +++ b/pkg/global/global.go @@ -21,3 +21,8 @@ type Security struct { } var Securities []*Security + +func init() { + Cron = cron.New(cron.WithSeconds()) + Cron.Start() +} diff --git a/pkg/global/store.go b/pkg/global/store.go index c2f66dc..d5a19b8 100644 --- a/pkg/global/store.go +++ b/pkg/global/store.go @@ -69,3 +69,7 @@ func NewStore() *TunStore { store := TunStore{sync.Map{}} return &store } + +func init() { + Store = NewStore() +} diff --git a/pkg/log/logger.go b/pkg/log/logger.go index 497dcc5..193d8cc 100644 --- a/pkg/log/logger.go +++ b/pkg/log/logger.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - "next-terminal/pkg/global" + "next-terminal/pkg/config" "github.com/labstack/echo/v4" "github.com/sirupsen/logrus" @@ -201,12 +201,11 @@ func NewLogger() Logrus { logger.SetOutput(io.MultiWriter(os.Stdout, src)) //设置日志级别 - if global.Config.Debug { + if config.GlobalCfg.Debug { logger.SetLevel(logrus.DebugLevel) } else { logger.SetLevel(logrus.InfoLevel) } - //设置日志格式 logger.SetFormatter(&logrus.TextFormatter{ TimestampFormat: "2006-01-02 15:04:05",