添加代码生成中route和gorm的自动注入

This commit is contained in:
LeonardWang
2021-03-19 23:24:55 +08:00
parent 9e0f95ec48
commit 0a3696ee01
8 changed files with 178 additions and 13 deletions

View File

@@ -134,6 +134,18 @@ func CreateTemp(autoCode model.AutoCodeStruct) (err error) {
return err
}
}
initializeGormFilePath := filepath.Join(global.GVA_CONFIG.AutoCode.Root,
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SInitialize, "gorm.go")
initializeRouterFilePath := filepath.Join(global.GVA_CONFIG.AutoCode.Root,
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SInitialize, "router.go")
err = utils.AutoInjectionCode(initializeGormFilePath, "MysqlTables", "model."+autoCode.StructName+"{},")
if err != nil {
return err
}
err = utils.AutoInjectionCode(initializeRouterFilePath, "Routers", "router.Init"+autoCode.StructName+"Router(PrivateGroup)")
if err != nil {
return err
}
return errors.New("创建代码成功并移动文件成功")
} else { // 打包
if err := utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil {

View File

@@ -10,6 +10,7 @@ import (
"github.com/spf13/viper"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"path/filepath"
)
//@author: [songzhibin97](https://github.com/songzhibin97)
@@ -154,5 +155,6 @@ func InitDB(conf request.InitDB) error {
_ = writeConfig(global.GVA_VP, baseSetting)
return err
}
global.GVA_CONFIG.AutoCode.Root, _ = filepath.Abs("..")
return nil
}