fix(be):使用初始化init 初始化一些参数
This commit is contained in:
parent
caa4ff1ffb
commit
d76f782a01
4
main.go
4
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()
|
||||
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -21,3 +21,8 @@ type Security struct {
|
||||
}
|
||||
|
||||
var Securities []*Security
|
||||
|
||||
func init() {
|
||||
Cron = cron.New(cron.WithSeconds())
|
||||
Cron.Start()
|
||||
}
|
||||
|
@ -69,3 +69,7 @@ func NewStore() *TunStore {
|
||||
store := TunStore{sync.Map{}}
|
||||
return &store
|
||||
}
|
||||
|
||||
func init() {
|
||||
Store = NewStore()
|
||||
}
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user