model_custom.tpl 925 B

12345678910111213141516171819202122232425262728
  1. package model
  2. {{if .Cache}}import (
  3. "github.com/zeromicro/go-zero/core/stores/cache"
  4. "github.com/zeromicro/go-zero/core/stores/monc"
  5. ){{else}}import "github.com/zeromicro/go-zero/core/stores/mon"{{end}}
  6. var _ {{.Type}}Model = (*custom{{.Type}}Model)(nil)
  7. type (
  8. // {{.Type}}Model is an interface to be customized, add more methods here,
  9. // and implement the added methods in custom{{.Type}}Model.
  10. {{.Type}}Model interface {
  11. {{.lowerType}}Model
  12. }
  13. custom{{.Type}}Model struct {
  14. *default{{.Type}}Model
  15. }
  16. )
  17. // New{{.Type}}Model returns a model for the mongo.
  18. func New{{.Type}}Model(url, db, collection string{{if .Cache}}, c cache.CacheConf{{end}}) {{.Type}}Model {
  19. conn := {{if .Cache}}monc{{else}}mon{{end}}.MustNewModel(url, db, collection{{if .Cache}}, c{{end}})
  20. return &custom{{.Type}}Model{
  21. default{{.Type}}Model: newDefault{{.Type}}Model(conn),
  22. }
  23. }