Modify: move aria2 into internal packages / migration version check

This commit is contained in:
HFO4
2020-02-22 12:18:49 +08:00
parent 1ac4767db7
commit a8272a66b7
27 changed files with 1849 additions and 81 deletions

View File

@@ -72,11 +72,39 @@ type cors struct {
var cfg *ini.File
const defaultConf = `
[System]
Mode = master
Listen = :5212
SessionSecret = {SessionSecret}
HashIDSalt = {HashIDSalt}
`
// Init 初始化配置文件
func Init(path string) {
var err error
//TODO 配置文件不存在时创建
//TODO 配置合法性验证
if path == "" || !util.Exists(path) {
// 创建初始配置文件
confContent := util.Replace(map[string]string{
"{SessionSecret}": util.RandStringRunes(64),
"{HashIDSalt}": util.RandStringRunes(64),
}, defaultConf)
f, err := util.CreatNestedFile("conf.ini")
if err != nil {
util.Log().Panic("无法创建配置文件, %s", err)
}
// 写入配置文件
_, err = f.WriteString(confContent)
if err != nil {
util.Log().Panic("无法写入配置文件, %s", err)
}
f.Close()
path = "conf.ini"
}
cfg, err = ini.Load(path)
if err != nil {
util.Log().Panic("无法解析配置文件 '%s': %s", path, err)