1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 19:43:49 +08:00

加载配置失败后备份源配置文件

配置结构升级不备份,我配置没了
This commit is contained in:
Ink-33 2020-08-29 17:49:40 +08:00
parent 9c65ff4dcd
commit f569225305
No known key found for this signature in database
GPG Key ID: 5D8B1D036EFB0D2E

View File

@ -2,6 +2,8 @@ package global
import ( import (
"encoding/json" "encoding/json"
"os"
"strconv"
"time" "time"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -117,6 +119,8 @@ func Load(p string) *JsonConfig {
err := json.Unmarshal([]byte(ReadAllText(p)), &c) err := json.Unmarshal([]byte(ReadAllText(p)), &c)
if err != nil { if err != nil {
log.Warnf("尝试加载配置文件 %v 时出现错误: %v", p, err) log.Warnf("尝试加载配置文件 %v 时出现错误: %v", p, err)
log.Infoln("原文件已备份")
os.Rename(p, p+".backup"+strconv.FormatInt(time.Now().Unix(), 10))
return nil return nil
} }
return &c return &c