MCPcopy Index your code
hub / github.com/ddev/ddev / TemplateStringToFile

Function TemplateStringToFile

pkg/fileutil/files.go:543–567  ·  view source on GitHub ↗

TemplateStringToFile takes a template string, runs templ.Execute on it, and writes it out to file

(content string, vars map[string]any, targetFilePath string)

Source from the content-addressed store, hash-verified

541
542// TemplateStringToFile takes a template string, runs templ.Execute on it, and writes it out to file
543func 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

Callers 15

WriteProjectEnvFileFunction · 0.92
TestDdevXdebugEnabledFunction · 0.92
TestEnvFileFunction · 0.92
PushGlobalTraefikConfigFunction · 0.92
configureTraefikForAppFunction · 0.92
TestHardenedStartFunction · 0.92
TestUseEphemeralPortFunction · 0.92
GenerateMutagenYmlMethod · 0.92

Calls 2

CheckCloseFunction · 0.92
ExecuteMethod · 0.65

Tested by 14

TestDdevXdebugEnabledFunction · 0.74
TestEnvFileFunction · 0.74
TestHardenedStartFunction · 0.74
TestUseEphemeralPortFunction · 0.74
TestCheckDockerAuthFunction · 0.74