logging
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/dryrun Pipeline was successful
ci/woodpecker/push/publish-tag Pipeline was successful
ci/woodpecker/push/publish-latest Pipeline was successful

This commit is contained in:
Michael Thomson 2024-06-19 11:46:22 -04:00
parent 1b528a85c8
commit 399cfd827d
No known key found for this signature in database
2 changed files with 17 additions and 1 deletions

View File

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

15
middleware/logging.go Normal file
View File

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