生成代码,逐步进行优化
This commit is contained in:
+10
-10
@@ -6,9 +6,7 @@ import (
|
||||
. "./common"
|
||||
. "./db"
|
||||
. "./log"
|
||||
"bytes"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"github.com/sirupsen/logrus"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -226,24 +224,25 @@ func (that *Application) SetConfig(configPath ...string) {
|
||||
|
||||
//文件如果损坏则不写入配置防止配置文件数据丢失
|
||||
if that.Error.GetError() == nil {
|
||||
var configByte bytes.Buffer
|
||||
//var configByte bytes.Buffer
|
||||
|
||||
err = json.Indent(&configByte, []byte(that.Config.ToJsonString()), "", "\t")
|
||||
//判断配置文件是否序列有变化,有则修改配置,无则不变
|
||||
//fmt.Println(len(btes))
|
||||
if len(btes) != 0 && configByte.String() == string(btes) {
|
||||
configStr := that.Config.ToJsonString()
|
||||
if len(btes) != 0 && configStr == string(btes) {
|
||||
return
|
||||
}
|
||||
//写入配置说明
|
||||
var configNoteByte bytes.Buffer
|
||||
_ = json.Indent(&configNoteByte, []byte(ConfigNote.ToJsonString()), "", "\t")
|
||||
//var configNoteByte bytes.Buffer
|
||||
configNoteStr := ConfigNote.ToJsonString()
|
||||
//_ = json.Indent(&configNoteByte, []byte(ConfigNote.ToJsonString()), "", "\t")
|
||||
|
||||
_ = os.MkdirAll(filepath.Dir(that.configPath), os.ModeDir)
|
||||
err = ioutil.WriteFile(that.configPath, configByte.Bytes(), os.ModeAppend)
|
||||
err = ioutil.WriteFile(that.configPath, []byte(configStr), os.ModePerm)
|
||||
if err != nil {
|
||||
that.Error.SetError(err)
|
||||
}
|
||||
_ = ioutil.WriteFile(filepath.Dir(that.configPath)+"/configNote.json", configNoteByte.Bytes(), os.ModeAppend)
|
||||
_ = ioutil.WriteFile(filepath.Dir(that.configPath)+"/configNote.json", []byte(configNoteStr), os.ModePerm)
|
||||
|
||||
}
|
||||
|
||||
@@ -451,7 +450,7 @@ func Init(config string) Application {
|
||||
appIns.SetCache()
|
||||
appIns.MakeCode = &code.MakeCode{}
|
||||
codeConfig := appIns.Config.GetMap("codeConfig")
|
||||
if codeConfig != nil {
|
||||
if codeConfig != nil && appIns.Config.GetInt("mode") == 2 {
|
||||
for k, _ := range codeConfig {
|
||||
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), appIns.Db)
|
||||
}
|
||||
@@ -476,6 +475,7 @@ func SetDB(appIns *Application) {
|
||||
func SetMysqlDB(appIns *Application, config Map) {
|
||||
|
||||
appIns.Db.Type = "mysql"
|
||||
appIns.Db.DBName = config.GetString("name")
|
||||
appIns.Db.Prefix = config.GetString("prefix")
|
||||
appIns.SetConnectDB(func(err ...*Error) (master, slave *sql.DB) {
|
||||
//master数据库配置
|
||||
|
||||
Reference in New Issue
Block a user