template.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package generate
  2. import (
  3. "fmt"
  4. "github.com/tal-tech/go-zero/tools/goctl/model/mongo/template"
  5. "github.com/tal-tech/go-zero/tools/goctl/util"
  6. "github.com/urfave/cli"
  7. )
  8. const (
  9. category = "mongo"
  10. modelTemplateFile = "model.tpl"
  11. errTemplateFile = "err.tpl"
  12. )
  13. var templates = map[string]string{
  14. modelTemplateFile: template.Text,
  15. errTemplateFile: template.Error,
  16. }
  17. // Category returns the mongo category.
  18. func Category() string {
  19. return category
  20. }
  21. // Clean cleans the mongo templates.
  22. func Clean() error {
  23. return util.Clean(category)
  24. }
  25. // Templates initializes the mongo templates.
  26. func Templates(_ *cli.Context) error {
  27. return util.InitTemplates(category, templates)
  28. }
  29. // RevertTemplate reverts the given template.
  30. func RevertTemplate(name string) error {
  31. content, ok := templates[name]
  32. if !ok {
  33. return fmt.Errorf("%s: no such file name", name)
  34. }
  35. return util.CreateTemplate(category, name, content)
  36. }
  37. // Update cleans and updates the templates.
  38. func Update() error {
  39. err := Clean()
  40. if err != nil {
  41. return err
  42. }
  43. return util.InitTemplates(category, templates)
  44. }