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