template.go 1.0 KB

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