backend: frontend: cleaned up the codebase and added more logging for debuging

This commit is contained in:
Patryk Hegenberg 2023-12-06 17:24:33 +01:00
parent faf7c2f782
commit 3a77eb1593
11 changed files with 152 additions and 38 deletions

View file

@ -7,15 +7,22 @@ import (
"net/http"
)
// ContactHandler handles the contact page request.
// It takes the content embed.FS as a parameter and returns an http.HandlerFunc.
// The returned http.HandlerFunc renders the contact page using the provided templates.
func ContactHandler(content embed.FS) http.HandlerFunc {
log.Print("ContactHandler called")
return func(w http.ResponseWriter, r *http.Request) {
log.Print("ContactHandler called")
// Parse the templates
tmpl, err := template.ParseFS(content, "templates/base.html", "templates/header.html", "templates/main.html", "templates/footer.html", "templates/about.html", "templates/contact.html")
if err != nil {
log.Printf("Template parsing error: %v\n", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Execute the contact template
err = tmpl.ExecuteTemplate(w, "contact", map[string]interface{}{
"Title": "Dungeons & Dragons Monster Generator",
})