embed templates in binary
All checks were successful
Build docker container / Build image (push) Successful in 26s
All checks were successful
Build docker container / Build image (push) Successful in 26s
This commit is contained in:
parent
c96249c0b5
commit
7c3c156139
6
main.go
6
main.go
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user