Skip to content

Commit 489c660

Browse files
committed
improve template embed
Signed-off-by: Markus Blaschke <mblaschke82@gmail.com>
1 parent 1f02137 commit 489c660

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

main.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"embed"
45
"encoding/base64"
56
"errors"
67
"fmt"
@@ -23,7 +24,6 @@ import (
2324

2425
"github.com/webdevops/azure-loganalytics-exporter/config"
2526
"github.com/webdevops/azure-loganalytics-exporter/loganalytics"
26-
"github.com/webdevops/azure-loganalytics-exporter/templates"
2727
)
2828

2929
const (
@@ -44,6 +44,9 @@ var (
4444

4545
metricCache *cache.Cache
4646

47+
//go:embed templates/*.html
48+
templates embed.FS
49+
4750
// Git version information
4851
gitCommit = "<unknown>"
4952
gitTag = "<unknown>"
@@ -160,10 +163,9 @@ func startHttpServer() {
160163
})
161164

162165
// report
163-
reportTmpl, err := template.New("report").Parse(templates.QueryHtml)
164-
if err != nil {
165-
log.Panicf("failed to parse query.html: %v", err.Error())
166-
}
166+
167+
tmpl := template.Must(template.ParseFS(templates, "templates/*.html"))
168+
167169
mux.HandleFunc("/query", func(w http.ResponseWriter, r *http.Request) {
168170
cspNonce := base64.StdEncoding.EncodeToString([]byte(uuid.New().String()))
169171

@@ -185,7 +187,7 @@ func startHttpServer() {
185187
Nonce: cspNonce,
186188
}
187189

188-
if err := reportTmpl.Execute(w, templatePayload); err != nil {
190+
if err := tmpl.ExecuteTemplate(w, "query.html", templatePayload); err != nil {
189191
log.Error(err)
190192
}
191193
})

templates/templates.go

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)