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

14
main.go
View File

@ -3,6 +3,9 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"io"
"log"
"net"
"net/http" "net/http"
"os/signal" "os/signal"
"syscall" "syscall"
@ -34,6 +37,10 @@ func run(ctx context.Context, cfg Config) error {
func listenAndServe(ctx context.Context, cfg Config) chan error { func listenAndServe(ctx context.Context, cfg Config) chan error {
s := http.Server{ 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) errc := make(chan error)
@ -44,3 +51,10 @@ func listenAndServe(ctx context.Context, cfg Config) chan error {
return errc 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)
}
}