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) + } +}