TemplateStringToFile takes a template string, runs templ.Execute on it, and writes it out to file
(content string, vars map[string]any, targetFilePath string)
| 541 | |
| 542 | // TemplateStringToFile takes a template string, runs templ.Execute on it, and writes it out to file |
| 543 | func TemplateStringToFile(content string, vars map[string]any, targetFilePath string) error { |
| 544 | templ := template.New("templateStringToFile:" + targetFilePath) |
| 545 | templ, err := templ.Parse(content) |
| 546 | if err != nil { |
| 547 | return err |
| 548 | } |
| 549 | |
| 550 | var doc bytes.Buffer |
| 551 | err = templ.Execute(&doc, vars) |
| 552 | if err != nil { |
| 553 | return err |
| 554 | } |
| 555 | |
| 556 | f, err := os.Create(targetFilePath) |
| 557 | if err != nil { |
| 558 | return err |
| 559 | } |
| 560 | defer util.CheckClose(f) |
| 561 | |
| 562 | _, err = f.WriteString(doc.String()) |
| 563 | if err != nil { |
| 564 | return nil |
| 565 | } |
| 566 | return nil |
| 567 | } |
| 568 | |
| 569 | // GlobFilenames looks in dirPath for files matching globPattern |
| 570 | // like "static_config.*.yaml" for example |