From 2d3f1ef95189c0c2dd3cd1c44ee8fbc8bd53fbab Mon Sep 17 00:00:00 2001 From: Patryk Hegenberg Date: Mon, 4 Dec 2023 11:14:37 +0100 Subject: [PATCH] added logging --- handlers/about_handler.go | 1 + handlers/add_monster_handler.go | 2 ++ handlers/contact_handler.go | 1 + handlers/form_handler.go | 1 + handlers/submit_handler.go | 2 ++ main.go | 4 ++-- 6 files changed, 9 insertions(+), 2 deletions(-) diff --git a/handlers/about_handler.go b/handlers/about_handler.go index 83e2b6c..12c02f8 100644 --- a/handlers/about_handler.go +++ b/handlers/about_handler.go @@ -8,6 +8,7 @@ import ( ) func AboutHandler(content embed.FS) http.HandlerFunc { + log.Print("AboutHandler called") return func(w http.ResponseWriter, r *http.Request) { tmpl, err := template.ParseFS(content, "templates/base.html", "templates/header.html", "templates/main.html", "templates/footer.html", "templates/about.html") if err != nil { diff --git a/handlers/add_monster_handler.go b/handlers/add_monster_handler.go index 222e7f4..bbec87b 100644 --- a/handlers/add_monster_handler.go +++ b/handlers/add_monster_handler.go @@ -2,11 +2,13 @@ package handlers import ( "ddServer/model" + "log" "net/http" "strconv" ) func AddMonster(Monsters *[]model.Monster) http.HandlerFunc { + log.Print("AddMonster called") return func(w http.ResponseWriter, r *http.Request) { // TODO if r.Method != http.MethodPost { diff --git a/handlers/contact_handler.go b/handlers/contact_handler.go index 407fe75..a683377 100644 --- a/handlers/contact_handler.go +++ b/handlers/contact_handler.go @@ -8,6 +8,7 @@ import ( ) func ContactHandler(content embed.FS) http.HandlerFunc { + log.Print("ContactHandler called") return func(w http.ResponseWriter, r *http.Request) { 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 { diff --git a/handlers/form_handler.go b/handlers/form_handler.go index dc57041..09df89b 100644 --- a/handlers/form_handler.go +++ b/handlers/form_handler.go @@ -8,6 +8,7 @@ import ( ) func FormHandler(content embed.FS, filename string) http.HandlerFunc { + log.Print("FormHandler called") return func(w http.ResponseWriter, r *http.Request) { tmpl, err := template.ParseFS(content, "templates/base.html", "templates/header.html", "templates/main.html", "templates/footer.html", "templates/monsterForm.html") if err != nil { diff --git a/handlers/submit_handler.go b/handlers/submit_handler.go index 744b879..02a6fde 100644 --- a/handlers/submit_handler.go +++ b/handlers/submit_handler.go @@ -5,6 +5,7 @@ import ( "embed" "encoding/json" "fmt" + "log" "net/http" "os" "sync" @@ -14,6 +15,7 @@ var mu sync.Mutex // submitHandler verarbeitet die Formulardaten func SubmitHandler(content embed.FS, chars *[]model.Character, Monsters *[]model.Monster, filename string) http.HandlerFunc { + log.Print("SubmitHandler called") return func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) diff --git a/main.go b/main.go index e91edee..d6db9e5 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,7 @@ import ( "ddServer/handlers" "ddServer/model" "embed" - "fmt" + "log" "net/http" "sync" ) @@ -28,6 +28,6 @@ func main() { http.HandleFunc("/about", handlers.AboutHandler(content)) http.HandleFunc("/contact", handlers.ContactHandler(content)) - fmt.Println("Server gestartet, erreichbar unter http://localhost:8080") + log.Print("Server gestartet, erreichbar unter http://localhost:8080") http.ListenAndServe(":8080", nil) }