feat: 读取配置文件时也使用 logrus
This commit is contained in:
@@ -4,8 +4,8 @@ import (
|
||||
"github.com/Mmx233/BitSrunLoginGo/models"
|
||||
"github.com/Mmx233/BitSrunLoginGo/v1/transfer"
|
||||
"github.com/Mmx233/tool"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/viper"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
@@ -14,7 +14,7 @@ var Config srunModels.Config
|
||||
|
||||
var Timeout time.Duration
|
||||
|
||||
func readConfig() error {
|
||||
func readConfig() {
|
||||
//配置文件默认值
|
||||
viper.SetDefault("form", srunTransfer.LoginForm{
|
||||
Domain: "www.msftconnecttest.com",
|
||||
@@ -45,23 +45,18 @@ func readConfig() error {
|
||||
if !tool.File.Exists(Flags.Path) {
|
||||
e := viper.WriteConfigAs(Flags.Path)
|
||||
if e != nil {
|
||||
log.Println("[init] 生成配置文件失败:", e)
|
||||
return e
|
||||
log.Fatalln("[init] 生成配置文件失败:", e)
|
||||
}
|
||||
log.Println("[init] 已生成配置文件,请编辑 '" + Flags.Path + "' 然后重试")
|
||||
log.Infoln("[init] 已生成配置文件,请编辑 '" + Flags.Path + "' 然后重试")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
//读取配置文件
|
||||
viper.SetConfigFile(Flags.Path)
|
||||
if e := viper.ReadInConfig(); e != nil {
|
||||
log.Println("[init] 读取配置文件失败:", e)
|
||||
return e
|
||||
log.Fatalln("[init] 读取配置文件失败:", e)
|
||||
}
|
||||
if e := viper.Unmarshal(&Config); e != nil {
|
||||
log.Println("[init] 解析配置文件失败:", e)
|
||||
return e
|
||||
log.Fatalln("[init] 解析配置文件失败:", e)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package global
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -9,9 +8,7 @@ func init() {
|
||||
initFlags()
|
||||
|
||||
//配置文件初始化
|
||||
if readConfig() != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
readConfig()
|
||||
|
||||
//初始化常变量
|
||||
Timeout = time.Duration(Config.Settings.Basic.Timeout) * time.Second
|
||||
|
||||
Reference in New Issue
Block a user