From 89eb422c173e1dd0c1b6004dc920358ca935dec3 Mon Sep 17 00:00:00 2001 From: unwox Date: Wed, 12 Jun 2024 20:20:42 +0600 Subject: add logging for http requests --- main.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main.go b/main.go index f12cf33..a9b47b8 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "net/http" + "time" ) func main() { @@ -24,6 +25,7 @@ func main() { mux.HandleFunc( route, func (wr http.ResponseWriter, r *http.Request) { + start := time.Now() resCh := w.Request(route, r) res := <- resCh for k, h := range res.Headers { @@ -31,6 +33,13 @@ func main() { } wr.WriteHeader(int(res.Code)) fmt.Fprint(wr, string(res.Body)) + log.Printf( + "%s %s (%s) -> %d\n", + r.Method, + r.URL.Path, + time.Now().Sub(start), + res.Code, + ) }, ) } -- cgit v1.2.3