Skip to content

Commit 2474c53

Browse files
committed
embed templates into binary
Signed-off-by: Markus Blaschke <[email protected]>
1 parent de3e7b8 commit 2474c53

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ FROM gcr.io/distroless/static as test
2525
USER 0:0
2626
WORKDIR /app
2727
COPY --from=build /go/src/github.com/webdevops/azure-resourcegraph-exporter/azure-resourcegraph-exporter .
28-
COPY --from=build /go/src/github.com/webdevops/azure-resourcegraph-exporter/templates ./templates
2928
RUN ["./azure-resourcegraph-exporter", "--help"]
3029

3130
#############################################

main.go

Lines changed: 6 additions & 2 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"
@@ -39,6 +40,9 @@ var (
3940

4041
metricCache *cache.Cache
4142

43+
//go:embed templates/*.html
44+
templates embed.FS
45+
4246
// Git version information
4347
gitCommit = "<unknown>"
4448
gitTag = "<unknown>"
@@ -152,7 +156,7 @@ func startHttpServer() {
152156
})
153157

154158
// report
155-
reportTmpl := template.Must(template.ParseFiles("./templates/query.html"))
159+
tmpl := template.Must(template.ParseFS(templates, "templates/*.html"))
156160
mux.HandleFunc("/query", func(w http.ResponseWriter, r *http.Request) {
157161
cspNonce := base64.StdEncoding.EncodeToString([]byte(uuid.New().String()))
158162

@@ -174,7 +178,7 @@ func startHttpServer() {
174178
Nonce: cspNonce,
175179
}
176180

177-
if err := reportTmpl.Execute(w, templatePayload); err != nil {
181+
if err := tmpl.ExecuteTemplate(w, "query.html", templatePayload); err != nil {
178182
log.Error(err)
179183
}
180184
})

0 commit comments

Comments
 (0)