fix: template without weird breakages

This commit is contained in:
decentral1se 2021-12-27 03:14:48 +01:00
parent c5a74e9f6b
commit 321ba1e0ec
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
1 changed files with 9 additions and 7 deletions

View File

@ -1,8 +1,10 @@
package recipe
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"text/template"
@ -74,20 +76,20 @@ recipe and domain in the sample environment config).
path.Join(config.RECIPES_DIR, recipeName, ".env.sample"),
}
for _, path := range toParse {
file, err := os.OpenFile(path, os.O_RDWR, 0664)
if err != nil {
logrus.Fatal(err)
}
defer file.Close()
tpl, err := template.ParseFiles(path)
if err != nil {
logrus.Fatal(err)
}
if err := tpl.Execute(file, meta); err != nil {
var templated bytes.Buffer
if err := tpl.Execute(&templated, meta); err != nil {
logrus.Fatal(err)
}
if err := ioutil.WriteFile(path, templated.Bytes(), 0644); err != nil {
logrus.Fatal(err)
}
}
newGitRepo := path.Join(config.RECIPES_DIR, recipeName)