feat(goctl): supports model code 'DO NOT EDIT' (#1728)

Resolves: #1710
This commit is contained in:
Fyn
2022-04-01 14:48:45 +08:00
committed by GitHub
parent 9c2d526a11
commit f4471846ff
8 changed files with 113 additions and 16 deletions

View File

@@ -1,7 +1,15 @@
package template
// Model defines a template for model
var Model = `package {{.pkg}}
import (
"fmt"
"github.com/zeromicro/go-zero/tools/goctl/util"
)
// ModelGen defines a template for model
var ModelGen = fmt.Sprintf(`%s
package {{.pkg}}
{{.imports}}
{{.vars}}
{{.types}}
@@ -11,4 +19,11 @@ var Model = `package {{.pkg}}
{{.update}}
{{.delete}}
{{.extraMethod}}
`
`, util.DoNotEditHead)
// ModelCustom defines a template for extension
var ModelCustom = fmt.Sprintf(`package {{.pkg}}
type {{.upperStartCamelObject}}Model interface {
{{.lowerStartCamelObject}}Model
}
`)

View File

@@ -3,7 +3,7 @@ package template
// Types defines a template for types in model
var Types = `
type (
{{.upperStartCamelObject}}Model interface{
{{.lowerStartCamelObject}}Model interface{
{{.method}}
}

View File

@@ -5,6 +5,8 @@ import "fmt"
// Vars defines a template for var block in model
var Vars = fmt.Sprintf(`
var (
_ {{.upperStartCamelObject}}Model = (*default{{.upperStartCamelObject}}Model)(nil)
{{.lowerStartCamelObject}}FieldNames = builder.RawFieldNames(&{{.upperStartCamelObject}}{}{{if .postgreSql}},true{{end}})
{{.lowerStartCamelObject}}Rows = strings.Join({{.lowerStartCamelObject}}FieldNames, ",")
{{.lowerStartCamelObject}}RowsExpectAutoSet = {{if .postgreSql}}strings.Join(stringx.Remove({{.lowerStartCamelObject}}FieldNames, {{if .autoIncrement}}"{{.originalPrimaryKey}}",{{end}} "%screate_time%s", "%supdate_time%s"), ","){{else}}strings.Join(stringx.Remove({{.lowerStartCamelObject}}FieldNames, {{if .autoIncrement}}"{{.originalPrimaryKey}}",{{end}} "%screate_time%s", "%supdate_time%s"), ","){{end}}