Commit f5692253 authored by Ink-33's avatar Ink-33

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

配置结构升级不备份,我配置没了
parent 9c65ff4d
...@@ -2,6 +2,8 @@ package global ...@@ -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 { ...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment