You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/tools/modelctl/model/modelgen/utiltemplate.go

35 lines
713 B
Go

package modelgen
const (
utilTemplateText = `package {{.Package}}
import (
"errors"
{{if .WithCache}}"github.com/tal-tech/go-zero/core/stores/redis"
"github.com/tal-tech/go-zero/core/stores/sqlc"
"github.com/tal-tech/go-zero/core/stores/sqlx"{{end}}
)
{{if .WithCache}}
type CachedModel struct {
table string
conn sqlx.SqlConn
rds *redis.Redis
sqlc.CachedConn
}
func NewCachedModel(conn sqlx.SqlConn, table string, rds *redis.Redis) *CachedModel {
return &CachedModel{
table: table,
conn: conn,
rds: rds,
CachedConn: sqlc.NewCachedConn(conn, rds),
}
}
{{end}}
var (
ErrNotFound = errors.New("not found")
)
`
)