diff --git a/main.go b/main.go index 04f8bf4..e40da03 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" "github.com/joho/godotenv" "michaelthomson.dev/mthomson/go-todos-app/handlers" + "michaelthomson.dev/mthomson/go-todos-app/middleware" "michaelthomson.dev/mthomson/go-todos-app/repositories" "michaelthomson.dev/mthomson/go-todos-app/services" ) @@ -130,7 +131,7 @@ func main() { server := http.Server{ Addr: "localhost:3000", - Handler: router, + Handler: middleware.LoggingMiddleware(router), } log.Fatal(server.ListenAndServe()) diff --git a/middleware/logging.go b/middleware/logging.go new file mode 100644 index 0000000..c73b656 --- /dev/null +++ b/middleware/logging.go @@ -0,0 +1,15 @@ +package middleware + +import ( + "log" + "net/http" +) + +func LoggingMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc( + func(w http.ResponseWriter, r *http.Request) { + log.Printf("[%s] %s", r.Method, r.URL.EscapedPath()) + next.ServeHTTP(w, r) + }, + ) +}