use go:embed to include forms.html into cpmpiled binary

This commit is contained in:
Patryk Hegenberg 2023-11-24 21:49:46 +01:00
parent f9295b74ee
commit bd3b2817f2

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"html/template" "html/template"
@ -97,6 +98,8 @@ type Source struct {
var ( var (
mu sync.Mutex mu sync.Mutex
chars []Character chars []Character
//go:embed forms.html
page embed.FS
) )
func main() { func main() {
@ -112,7 +115,7 @@ func main() {
// formHandler zeigt das Formular an // formHandler zeigt das Formular an
func formHandler(filename string) http.HandlerFunc { func formHandler(filename string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
tmpl, err := template.ParseFiles("forms.html") tmpl, err := template.ParseFS(page, "forms.html")
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return