/
generateA2harb.go
45 lines (37 loc) · 1.03 KB
/
generateA2harb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright © 2017 Chef Software
package main
import (
"bytes"
"container/list"
"io/ioutil"
"strings"
"text/template"
"github.com/pkg/errors"
)
func getSingleErrorFromList(l *list.List) error {
errorString := ""
for e := l.Front(); e != nil; e = e.Next() {
errorString = errorString + "\n" + e.Value.(string)
}
return errors.New(errorString)
}
func writeToA2HARBFile(template string, path string) {
err := ioutil.WriteFile(path, []byte(template), 0600)
if err != nil {
writer.Printf("Writing into A2HA.rb file failed\n")
}
writer.Printf("Config written to %s\n", path)
}
func renderSettingsToA2HARBFile(templateName string, data map[string]interface{}, state string) string {
data["State"] = state
temp := template.Must(template.New("init").
Funcs(template.FuncMap{"StringsJoin": strings.Join}).
Parse(templateName))
var buf bytes.Buffer
err := temp.Execute(&buf, data)
if err != nil {
writer.Printf("some error occurred while rendering template \n %s", err)
}
finalTemplate := buf.String()
return finalTemplate
}