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 (
|
2022-04-04 13:12:05 +08:00
|
|
|
_ "embed"
|
|
|
|
|
2022-02-09 17:22:52 +08:00
|
|
|
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
2020-11-09 18:02:16 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
category = "docker"
|
|
|
|
dockerTemplateFile = "docker.tpl"
|
|
|
|
)
|
|
|
|
|
2022-04-04 13:12:05 +08:00
|
|
|
//go:embed docker.tpl
|
|
|
|
var dockerTemplate string
|
|
|
|
|
2021-02-26 16:11:47 +08:00
|
|
|
// Clean deletes all templates files
|
2020-12-11 18:53:40 +08:00
|
|
|
func Clean() error {
|
2022-01-03 21:32:40 +08:00
|
|
|
return pathx.Clean(category)
|
2020-12-11 18:53:40 +08:00
|
|
|
}
|
|
|
|
|
2021-02-26 16:11:47 +08:00
|
|
|
// GenTemplates creates docker template files
|
2022-05-07 15:40:11 +08:00
|
|
|
func GenTemplates() error {
|
2020-12-11 18:53:40 +08:00
|
|
|
return initTemplate()
|
|
|
|
}
|
|
|
|
|
2021-02-26 16:11:47 +08:00
|
|
|
// Category returns the const string of docker category
|
2020-12-11 18:53:40 +08:00
|
|
|
func Category() string {
|
|
|
|
return category
|
|
|
|
}
|
|
|
|
|
2021-02-26 16:11:47 +08:00
|
|
|
// RevertTemplate recovers the deleted template files
|
2020-12-11 18:53:40 +08:00
|
|
|
func RevertTemplate(name string) error {
|
2022-01-03 21:32:40 +08:00
|
|
|
return pathx.CreateTemplate(category, name, dockerTemplate)
|
2020-12-11 18:53:40 +08:00
|
|
|
}
|
|
|
|
|
2021-02-26 16:11:47 +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 {
|
2022-01-03 21:32:40 +08:00
|
|
|
return pathx.InitTemplates(category, map[string]string{
|
2020-11-09 18:02:16 +08:00
|
|
|
dockerTemplateFile: dockerTemplate,
|
|
|
|
})
|
|
|
|
}
|