template.go 987 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package docker
  2. import (
  3. _ "embed"
  4. "github.com/urfave/cli"
  5. "github.com/zeromicro/go-zero/tools/goctl/util/pathx"
  6. )
  7. const (
  8. category = "docker"
  9. dockerTemplateFile = "docker.tpl"
  10. )
  11. //go:embed docker.tpl
  12. var dockerTemplate string
  13. // Clean deletes all templates files
  14. func Clean() error {
  15. return pathx.Clean(category)
  16. }
  17. // GenTemplates creates docker template files
  18. func GenTemplates(_ *cli.Context) error {
  19. return initTemplate()
  20. }
  21. // Category returns the const string of docker category
  22. func Category() string {
  23. return category
  24. }
  25. // RevertTemplate recovers the deleted template files
  26. func RevertTemplate(name string) error {
  27. return pathx.CreateTemplate(category, name, dockerTemplate)
  28. }
  29. // Update deletes and creates new template files
  30. func Update() error {
  31. err := Clean()
  32. if err != nil {
  33. return err
  34. }
  35. return initTemplate()
  36. }
  37. func initTemplate() error {
  38. return pathx.InitTemplates(category, map[string]string{
  39. dockerTemplateFile: dockerTemplate,
  40. })
  41. }