log access
parent
4c4d92478d
commit
bf7e067628
16
main.go
16
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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue