1 Star 0 Fork 0

mchong/gin-admin-cli

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
model_inject.go 760 Bytes
一键复制 编辑 原始数据 按行查看 历史
Lyric 提交于 2019-08-27 10:19 +08:00 . Add generate command
package generate
import (
"context"
"fmt"
)
func getModelInjectFileName(dir string) string {
fullname := fmt.Sprintf("%s/internal/app/model/impl/gorm/gorm.go", dir)
return fullname
}
// 插入model注入文件
func insertModelInject(ctx context.Context, pkgName, dir, name, comment string) error {
fullname := getModelInjectFileName(dir)
err := insertFileContent(fullname, "func AutoMigrate", "entity.", fmt.Sprintf("new(entity.%s),\n", name))
if err != nil {
return err
}
err = insertFileContent(fullname, "func Inject", "container.Provide", fmt.Sprintf("container.Provide(imodel.New%s, dig.As(new(model.I%s)))\n", name, name))
if err != nil {
return err
}
fmt.Printf("文件[%s]写入成功\n", fullname)
return execGoFmt(fullname)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mchongjs/gin-admin-cli.git
git@gitee.com:mchongjs/gin-admin-cli.git
mchongjs
gin-admin-cli
gin-admin-cli
a13bc20d66c4

搜索帮助