template.go 958 B

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