feat: 读取配置文件时也使用 logrus

This commit is contained in:
Mmx233
2022-08-15 23:47:21 +08:00
parent b5d3563309
commit ad36fc3582
2 changed files with 7 additions and 15 deletions

View File

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