summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2024-06-12 20:20:42 +0600
committerunwox <me@unwox.com>2024-06-12 20:23:11 +0600
commit89eb422c173e1dd0c1b6004dc920358ca935dec3 (patch)
tree787e6fb94542236edc4644cdfd6630142c0498a3 /main.go
parentb173639424aa962185801cb70512d1ddd83dca3a (diff)
add logging for http requests
Diffstat (limited to 'main.go')
-rw-r--r--main.go9
1 files changed, 9 insertions, 0 deletions
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,
+ )
},
)
}