template.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package new
  2. import (
  3. "fmt"
  4. "github.com/tal-tech/go-zero/tools/goctl/util"
  5. "github.com/urfave/cli"
  6. )
  7. const (
  8. category = "newapi"
  9. apiTemplateFile = "newtemplate.tpl"
  10. )
  11. var templates = map[string]string{
  12. apiTemplateFile: apiTemplate,
  13. }
  14. // Category returns the category of the api files.
  15. func Category() string {
  16. return category
  17. }
  18. // Clean cleans the generated deployment files.
  19. func Clean() error {
  20. return util.Clean(category)
  21. }
  22. // GenTemplates generates api template files.
  23. func GenTemplates(_ *cli.Context) error {
  24. return util.InitTemplates(category, templates)
  25. }
  26. // RevertTemplate reverts the given template file to the default value.
  27. func RevertTemplate(name string) error {
  28. content, ok := templates[name]
  29. if !ok {
  30. return fmt.Errorf("%s: no such file name", name)
  31. }
  32. return util.CreateTemplate(category, name, content)
  33. }
  34. // Update updates the template files to the templates built in current goctl.
  35. func Update() error {
  36. err := Clean()
  37. if err != nil {
  38. return err
  39. }
  40. return util.InitTemplates(category, templates)
  41. }