Parsing data from YAML and outputting HTML

This commit is contained in:
Oliver Davies 2025-09-29 19:59:05 +01:00
parent 37ad11a9b4
commit e2b5cdc9d9
7 changed files with 50 additions and 0 deletions

33
go-templates/main.go Normal file
View file

@ -0,0 +1,33 @@
package main
import (
"log"
"os"
"text/template"
"gopkg.in/yaml.v3"
)
func check(err error) {
if err != nil {
log.Fatalf("error: %v", err)
}
}
func main() {
out, err := os.Create("index.html")
check(err)
defer out.Close()
data := map[string]any{}
buf, err := os.ReadFile("data.yaml")
check(err)
err = yaml.Unmarshal(buf, &data)
check(err)
t, err := template.ParseGlob("tmpl/*")
check(err)
err = t.Execute(out, data)
check(err)
}