fix(be):使用初始化init 初始化一些参数

This commit is contained in:
neverteaser 2021-03-20 22:38:22 +08:00 committed by dushixiang
parent caa4ff1ffb
commit d76f782a01
5 changed files with 20 additions and 6 deletions

View File

@ -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()

View File

@ -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()
}

View File

@ -21,3 +21,8 @@ type Security struct {
}
var Securities []*Security
func init() {
Cron = cron.New(cron.WithSeconds())
Cron.Start()
}

View File

@ -69,3 +69,7 @@ func NewStore() *TunStore {
store := TunStore{sync.Map{}}
return &store
}
func init() {
Store = NewStore()
}

View File

@ -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",