model_custom.tpl 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. {{if .Easy}}
  7. const {{.Type}}CollectionName = "{{.snakeType}}"
  8. {{end}}
  9. var _ {{.Type}}Model = (*custom{{.Type}}Model)(nil)
  10. type (
  11. // {{.Type}}Model is an interface to be customized, add more methods here,
  12. // and implement the added methods in custom{{.Type}}Model.
  13. {{.Type}}Model interface {
  14. {{.lowerType}}Model
  15. }
  16. custom{{.Type}}Model struct {
  17. *default{{.Type}}Model
  18. }
  19. )
  20. // New{{.Type}}Model returns a model for the mongo.
  21. {{if .Easy}}func New{{.Type}}Model(url, db string{{if .Cache}}, c cache.CacheConf{{end}}) {{.Type}}Model {
  22. conn := {{if .Cache}}monc{{else}}mon{{end}}.MustNewModel(url, db, {{.Type}}CollectionName{{if .Cache}}, c{{end}})
  23. return &custom{{.Type}}Model{
  24. default{{.Type}}Model: newDefault{{.Type}}Model(conn),
  25. }
  26. }{{else}}func New{{.Type}}Model(url, db, collection string{{if .Cache}}, c cache.CacheConf{{end}}) {{.Type}}Model {
  27. conn := {{if .Cache}}monc{{else}}mon{{end}}.MustNewModel(url, db, collection{{if .Cache}}, c{{end}})
  28. return &custom{{.Type}}Model{
  29. default{{.Type}}Model: newDefault{{.Type}}Model(conn),
  30. }
  31. }{{end}}