diff --git a/code/makecode.go b/code/makecode.go index 1d03fed..1d581e1 100644 --- a/code/makecode.go +++ b/code/makecode.go @@ -68,6 +68,14 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) { for _, v := range ColumnNameType { that.RuleConfig = append(that.RuleConfig, Map{"name": v.Name, "list": v.List, "edit": v.Edit, "info": v.Info, "must": v.Must, "strict": v.Strict, "type": v.Type}) } + if db != nil { + _ = os.MkdirAll(filepath.Dir(config.GetString("rule")), os.ModeDir) + err = ioutil.WriteFile(config.GetString("rule"), []byte(ObjToStr(that.RuleConfig)), os.ModePerm) + if err != nil { + that.Error.SetError(err) + } + } + that.Error.SetError(errors.New("rule配置文件不存在,或者配置出错,使用缺省默认配置")) } @@ -540,12 +548,6 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) { } } - _ = os.MkdirAll(filepath.Dir(config.GetString("rule")), os.ModeDir) - err = ioutil.WriteFile(config.GetString("rule"), []byte(ObjToStr(that.RuleConfig)), os.ModePerm) - if err != nil { - that.Error.SetError(err) - } - //写入配置文件 //err = json.Indent(&configByte, []byte(that.Config.ToJsonString()), "", "\t") _ = os.MkdirAll(filepath.Dir(config.GetString("config")), os.ModeDir) diff --git a/example/config/config.json b/example/config/config.json index 6a6eec4..ad7e303 100644 --- a/example/config/config.json +++ b/example/config/config.json @@ -41,7 +41,7 @@ "5": "数据结果异常" }, "imgPath": "img/2006/01/02/", - "mode": 0, + "mode": 2, "port": "8081", "sessionName": "HOTIME", "smsKey": "b0eb4bf0198b9983cffcb85b69fdf4fa",