added content to about and contact page and added main-handler to achive spa-functionality

This commit is contained in:
Patryk Hegenberg 2023-12-06 09:12:49 +01:00
parent d60d1df51e
commit b82e138c4d
6 changed files with 102 additions and 4 deletions

28
handlers/main_handler.go Normal file
View file

@ -0,0 +1,28 @@
package handlers
import (
"embed"
"html/template"
"log"
"net/http"
)
// MainHandler
func MainHandler(content embed.FS) http.HandlerFunc {
log.Print("MainHandler called")
return func(w http.ResponseWriter, r *http.Request) {
tmpl, err := template.ParseFS(content, "templates/main.html", "templates/monsterForm.html", "templates/monster.html", "templates/monsterTable.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = tmpl.ExecuteTemplate(w, "main", map[string]interface{}{
"Title": "Dungeons & Dragons Monster Generator",
})
if err != nil {
log.Printf("Template execution error: %v\n", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}