Files
BitSrunLoginGo/Util/init.go
Mmx f0c3df85da fix:修复bug若干
1、修复日志不追加的问题
2、修复未初始化时Demo mode读取panic问题
3、修复重构时文件名也被替换的问题
4、修复file包逻辑漏洞
5、log输出文件名新增时间戳
2021-05-05 11:19:13 +08:00

42 lines
789 B
Go

package Util
import (
"Mmx/Global"
"Mmx/Modles"
"log"
"os"
)
func init() {
//配置文件初始化
Path := "Config.json"
if !File.Exists(Path) {
if err := File.WriteJson(Path, &Modles.Config{ //默认值
From: Modles.LoginForm{
Domain: "www.msftconnecttest.com",
UserName: "",
PassWord: "",
},
Meta: Modles.LoginMeta{
N: "200",
VType: "1",
Acid: "5",
Enc: "srun_bx1",
},
}); err != nil {
log.Println("创建配置文件失败:\n", err.Error())
os.Exit(1)
}
log.Println("已生成配置文件,请编辑 'Config.json' 然后重试")
os.Exit(0)
}
var c Modles.Config
if err := File.ReadJson(Path, &c); err != nil {
log.Println("读取配置文件失败:\n", err.Error())
os.Exit(1)
}
Global.Config = &c
}