This repository has been archived on 2023-05-06. You can view files and clone it, but cannot push or open issues or pull requests.
helix/internal/stacks/templates.go

25 lines
571 B
Go
Raw Normal View History

package stacks
import (
"fmt"
"os"
"text/template"
)
// generateFile renders a given template to a given filepath.
func generateFile(data interface{}, templateString, templateName, path string) error {
file, err := os.Create(path)
if err != nil {
return fmt.Errorf("unable to create the file '%s'...\n%v", path, err)
}
defer file.Close()
tmpl := template.Must(template.New(templateName).Parse(templateString))
if err = tmpl.Execute(file, data); err != nil {
return fmt.Errorf("unable to execute the template at '%s'...\n%v", path, err)
}
return nil
}