From bf7e067628531ed405b4a944df4005a717ae6b74 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:39:56 -0600 Subject: [PATCH] log access --- main.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 43eb62f..3375e24 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,9 @@ package main import ( "context" "fmt" + "io" + "log" + "net" "net/http" "os/signal" "syscall" @@ -33,7 +36,11 @@ func run(ctx context.Context, cfg Config) error { func listenAndServe(ctx context.Context, cfg Config) chan error { s := http.Server{ - Addr: fmt.Sprintf(":%d", cfg.Port), + Addr: fmt.Sprintf(":%d", cfg.Port), + Handler: http.HandlerFunc(newHandler(cfg)), + BaseContext: func(net.Listener) context.Context { + return ctx + }, } errc := make(chan error) @@ -44,3 +51,10 @@ func listenAndServe(ctx context.Context, cfg Config) chan error { return errc } + +func newHandler(cfg Config) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + b, _ := io.ReadAll(r.Body) + log.Printf("%s %s | %s", r.Method, r.URL, b) + } +}