diff --git a/handlers/main_handler.go b/handlers/main_handler.go index 06a3821..ad74291 100644 --- a/handlers/main_handler.go +++ b/handlers/main_handler.go @@ -1,6 +1,7 @@ package handlers import ( + "ddServer/model" "embed" "html/template" "log" @@ -8,7 +9,7 @@ import ( ) // MainHandler -func MainHandler(content embed.FS) http.HandlerFunc { +func MainHandler(content embed.FS, monsters *[]model.Monster) 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") @@ -17,8 +18,12 @@ func MainHandler(content embed.FS) http.HandlerFunc { return } + mu.Lock() + defer mu.Unlock() + err = tmpl.ExecuteTemplate(w, "main", map[string]interface{}{ - "Title": "Dungeons & Dragons Monster Generator", + "Title": "Dungeons & Dragons Monster Generator", + "Monsters": *monsters, }) if err != nil { log.Printf("Template execution error: %v\n", err) diff --git a/main.go b/main.go index a990799..2060623 100644 --- a/main.go +++ b/main.go @@ -28,7 +28,7 @@ func main() { http.HandleFunc("/submit", handlers.SubmitHandler(content, &chars, &Monsters, filename)) http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.FS(content)))) http.HandleFunc("/addMonster", handlers.AddMonster(&Monsters)) - http.HandleFunc("/main", handlers.MainHandler(content)) + http.HandleFunc("/main", handlers.MainHandler(content, &Monsters)) http.HandleFunc("/about", handlers.AboutHandler(content)) http.HandleFunc("/contact", handlers.ContactHandler(content)) http.HandleFunc("/monsterTable", handlers.MonsterTableHandler(content, &Monsters)) diff --git a/templates/header.html b/templates/header.html index fb33787..755b7ae 100644 --- a/templates/header.html +++ b/templates/header.html @@ -11,15 +11,15 @@
-
+