2 Star 1 Fork 3

Lyric / gin-admin-cli

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
model.go 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
Lyric 提交于 2019-08-26 16:07 . Add generate
package generate
import (
"context"
"fmt"
"github.com/LyricTian/gin-admin-cli/util"
)
func getModelFileName(dir, name string) string {
fullname := fmt.Sprintf("%s/internal/app/model/m_%s.go", dir, util.ToLowerUnderlinedNamer(name))
return fullname
}
// 生成model文件
func genModel(ctx context.Context, pkgName, dir, name, comment string) error {
data := map[string]interface{}{
"PkgName": pkgName,
"Name": name,
"Comment": comment,
}
buf, err := execParseTpl(modelTpl, data)
if err != nil {
return err
}
fullname := getModelFileName(dir, name)
err = createFile(ctx, fullname, buf)
if err != nil {
return err
}
fmt.Printf("文件[%s]写入成功\n", fullname)
return execGoFmt(fullname)
}
const modelTpl = `
package model
import (
"context"
"{{.PkgName}}/internal/app/schema"
)
// I{{.Name}} {{.Comment}}存储接口
type I{{.Name}} interface {
// 查询数据
Query(ctx context.Context, params schema.{{.Name}}QueryParam, opts ...schema.{{.Name}}QueryOptions) (*schema.{{.Name}}QueryResult, error)
// 查询指定数据
Get(ctx context.Context, recordID string, opts ...schema.{{.Name}}QueryOptions) (*schema.{{.Name}}, error)
// 创建数据
Create(ctx context.Context, item schema.{{.Name}}) error
// 更新数据
Update(ctx context.Context, recordID string, item schema.{{.Name}}) error
// 删除数据
Delete(ctx context.Context, recordID string) error
}
`
Go
1
https://gitee.com/lyric/gin-admin-cli.git
git@gitee.com:lyric/gin-admin-cli.git
lyric
gin-admin-cli
gin-admin-cli
v1.0.0

搜索帮助