12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package template
- import (
- "fmt"
- "github.com/zeromicro/go-zero/tools/goctl/util"
- )
- // ModelCustom defines a template for extension
- const ModelCustom = `package {{.pkg}}
- {{if .withCache}}
- import (
- "github.com/zeromicro/go-zero/core/stores/cache"
- "github.com/zeromicro/go-zero/core/stores/sqlx"
- )
- {{else}}
- import "github.com/zeromicro/go-zero/core/stores/sqlx"
- {{end}}
- var _ {{.upperStartCamelObject}}Model = (*custom{{.upperStartCamelObject}}Model)(nil)
- type (
- // {{.upperStartCamelObject}}Model is an interface to be customized, add more methods here,
- // and implement the added methods in custom{{.upperStartCamelObject}}Model.
- {{.upperStartCamelObject}}Model interface {
- {{.lowerStartCamelObject}}Model
- }
- custom{{.upperStartCamelObject}}Model struct {
- *default{{.upperStartCamelObject}}Model
- }
- )
- // New{{.upperStartCamelObject}}Model returns a model for the database table.
- func New{{.upperStartCamelObject}}Model(conn sqlx.SqlConn{{if .withCache}}, c cache.CacheConf{{end}}) {{.upperStartCamelObject}}Model {
- return &custom{{.upperStartCamelObject}}Model{
- default{{.upperStartCamelObject}}Model: new{{.upperStartCamelObject}}Model(conn{{if .withCache}}, c{{end}}),
- }
- }
- `
- // ModelGen defines a template for model
- var ModelGen = fmt.Sprintf(`%s
- package {{.pkg}}
- {{.imports}}
- {{.vars}}
- {{.types}}
- {{.new}}
- {{.delete}}
- {{.find}}
- {{.insert}}
- {{.update}}
- {{.extraMethod}}
- {{.tableName}}
- `, util.DoNotEditHead)
|