log access

main
Bel LaPointe 2024-04-11 16:39:56 -06:00
parent 4c4d92478d
commit bf7e067628
1 changed files with 15 additions and 1 deletions

16
main.go
View File

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