From ef554197e624c867dbbd0a9edc7cd0be335877f3 Mon Sep 17 00:00:00 2001 From: Joren Schipman Date: Sat, 4 May 2024 01:39:28 +0200 Subject: [PATCH] Add logs --- loothandler.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/loothandler.go b/loothandler.go index 7607dd2..ccafe24 100644 --- a/loothandler.go +++ b/loothandler.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "html/template" "io/ioutil" "log" @@ -20,12 +21,20 @@ type PageData struct { } func main() { - http.HandleFunc("/", loginHandler) - http.HandleFunc("/loot", lootHandler) - http.HandleFunc("/logout", logoutHandler) - http.HandleFunc("/files/", fileHandler) + http.HandleFunc("/", logMiddleware(loginHandler)) + http.HandleFunc("/loot", logMiddleware(lootHandler)) + http.HandleFunc("/logout", logMiddleware(logoutHandler)) + http.HandleFunc("/files/", logMiddleware(fileHandler)) - log.Fatal(http.ListenAndServe(":8080", nil)) + log.Fatal(http.ListenAndServe(":5647", nil)) + fmt.Println("Server started") +} + +func logMiddleware(next http.HandlerFunc) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + log.Printf("[%s] %s %s\n", r.Method, r.RemoteAddr, r.URL.Path) + next(w, r) + } } func loginHandler(w http.ResponseWriter, r *http.Request) {