feat: 更换配置文件实现包

This commit is contained in:
Mmx
2021-09-19 22:56:06 +08:00
parent 83d020c928
commit e4669ea4ae
4 changed files with 33 additions and 58 deletions

View File

@@ -3,6 +3,7 @@ package util
import (
"autoLogin/global"
"autoLogin/models"
"github.com/Mmx233/config"
"github.com/Mmx233/tool"
"log"
"os"
@@ -11,29 +12,35 @@ import (
func init() {
//配置文件初始化
Path := "Config.json"
var c models.Config
if !File.Exists(Path) {
if err := File.WriteJson(
Path,
c.FillDefault(),
); err != nil {
log.Println("创建配置文件失败:\n", err.Error())
os.Exit(1)
if e := config.Load(config.Options{
Config: &global.Config,
Default: &models.Config{
From: models.LoginForm{
Domain: "www.msftconnecttest.com",
UserType: "cmcc",
},
Meta: models.LoginMeta{
N: "200",
Type: "1",
Acid: "5",
Enc: "srun_bx1",
},
Settings: models.Settings{
Timeout: 1,
},
},
Path: "Config.json",
FillDefault: true,
Overwrite: true,
}); e != nil {
if config.IsNew(e) {
log.Println("已生成配置文件,请编辑 'Config.json' 然后重试")
os.Exit(0)
}
log.Println("已生成配置文件,请编辑 'Config.json' 然后重试")
os.Exit(0)
}
if err := File.ReadJson(Path, &c); err != nil {
log.Println("读取配置文件失败:\n", err.Error())
log.Println("读取配置文件失败:\n", e.Error())
os.Exit(1)
}
_ = File.WriteJson(Path, c.FillDefault())
global.Config = &c
//http工具设定
tool.HTTP.Options.Timeout = 3 * time.Second
}