Remove map allocation in index template

We have only a single variable left, better to remove the map/loop for now.
This commit is contained in:
Vic Demuzere 2021-09-26 15:39:20 +02:00
parent 236c6a8dcb
commit fdd9eb6092
No known key found for this signature in database
GPG Key ID: 5B9EA1616690CF94
2 changed files with 4 additions and 8 deletions

View File

@ -41,9 +41,7 @@
document.addEventListener('DOMContentLoaded', () => window.refreshTheme())
// Template variable from Golang process
{{- range $key, $value := .Vars }}
const {{ $key }} = "{{ $value }}"
{{- end }}
const version = "{{ .Version }}"
</script>
</head>
<body>

View File

@ -120,12 +120,10 @@ func handleIndex(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Security-Policy", cspHeader)
w.Header().Set("X-Content-Type-Options", "nosniff")
if err = tpl.Execute(w, struct {
Vars map[string]string
if err := indexTpl.Execute(w, struct {
Version string
}{
Vars: map[string]string{
"version": version,
},
Version: version,
}); err != nil {
http.Error(w, errors.Wrap(err, "executing template").Error(), http.StatusInternalServerError)
return