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 }