-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (36 loc) · 854 Bytes
/
main.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
package main
import (
"io"
"log"
"os"
"encoding/json"
"text/template"
)
func main() {
// read command-line argument JSON file
jsonPath := os.Args[1]
jsonRaw, err := os.ReadFile(jsonPath)
if err != nil {
log.Fatalf("error reading values: %v", err)
}
var values interface{}
err = json.Unmarshal(jsonRaw, &values)
if err != nil {
log.Fatalf("error unmarshalling values: %v", err)
}
// read a Go template from stdin
tmplRaw, err := io.ReadAll(os.Stdin)
if err != nil {
log.Fatalf("error reading template: %v", err)
}
// parse the template
tmpl, err := template.New("template").Parse(string(tmplRaw))
if err != nil {
log.Fatalf("error parsing template: %v", err)
}
// execute the template and write to stdout
err = tmpl.Execute(os.Stdout, values)
if err != nil {
log.Fatalf("error executing template: %v", err)
}
}