embed templates in binary
All checks were successful
Build docker container / Build image (push) Successful in 26s

This commit is contained in:
Mans Ziesel 2024-06-03 13:56:16 +02:00
parent c96249c0b5
commit 7c3c156139

View File

@ -2,6 +2,7 @@ package main
import (
"context"
"embed"
"encoding/json"
"fmt"
"html/template"
@ -27,6 +28,9 @@ type contextKey string
const netAddrKey = contextKey("netAddr")
//go:embed templates/*
var templatesFS embed.FS
func RealIpMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
netAddr := extractNetAddress(r)
@ -85,7 +89,7 @@ func mainHandler(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/":
fp := path.Join("templates", "index.html")
tmpl, err := template.ParseFiles(fp)
tmpl, err := template.ParseFS(templatesFS, fp)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return