From 8b73652c9b1b5f9585a3539537991b702589249a Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Mon, 26 Oct 2026 18:28:37 +0000 Subject: [PATCH] add basic logging middleware --- http-utils.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/http-utils.go b/http-utils.go index 604a105..e2b6861 100644 --- a/http-utils.go +++ b/http-utils.go @@ -4,7 +4,9 @@ import ( "bytes" "encoding/json" "html/template" + "log" "net/http" + "time" ) func HTTPExecuteHTMLTemplate(w http.ResponseWriter, t *template.Template, name string, d any) { @@ -45,3 +47,11 @@ func HTTPWriteJson(w http.ResponseWriter, code int, obj any) { return } } + +func LoggingMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + start := time.Now() + next.ServeHTTP(w, r) + log.Printf("%s %s %s", r.Method, r.URL.Path, time.Since(start)) + }) +}