go-zero/tools/goctl/docker/template.go

52 lines
948 B
Go
Raw Normal View History

2020-11-09 18:02:16 +08:00
package docker
2020-07-29 17:11:41 +08:00
2020-11-09 18:02:16 +08:00
import (
_ "embed"
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
2020-11-09 18:02:16 +08:00
)
const (
category = "docker"
dockerTemplateFile = "docker.tpl"
)
//go:embed docker.tpl
var dockerTemplate string
// Clean deletes all templates files
2020-12-11 18:53:40 +08:00
func Clean() error {
return pathx.Clean(category)
2020-12-11 18:53:40 +08:00
}
// GenTemplates creates docker template files
func GenTemplates() error {
2020-12-11 18:53:40 +08:00
return initTemplate()
}
// Category returns the const string of docker category
2020-12-11 18:53:40 +08:00
func Category() string {
return category
}
// RevertTemplate recovers the deleted template files
2020-12-11 18:53:40 +08:00
func RevertTemplate(name string) error {
return pathx.CreateTemplate(category, name, dockerTemplate)
2020-12-11 18:53:40 +08:00
}
// Update deletes and creates new template files
2020-12-11 18:53:40 +08:00
func Update() error {
err := Clean()
if err != nil {
return err
}
return initTemplate()
}
func initTemplate() error {
return pathx.InitTemplates(category, map[string]string{
2020-11-09 18:02:16 +08:00
dockerTemplateFile: dockerTemplate,
})
}