logging
This commit is contained in:
parent
1b528a85c8
commit
399cfd827d
3
main.go
3
main.go
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/jackc/pgx/v5/pgxpool"
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"michaelthomson.dev/mthomson/go-todos-app/handlers"
|
"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/repositories"
|
||||||
"michaelthomson.dev/mthomson/go-todos-app/services"
|
"michaelthomson.dev/mthomson/go-todos-app/services"
|
||||||
)
|
)
|
||||||
@ -130,7 +131,7 @@ func main() {
|
|||||||
|
|
||||||
server := http.Server{
|
server := http.Server{
|
||||||
Addr: "localhost:3000",
|
Addr: "localhost:3000",
|
||||||
Handler: router,
|
Handler: middleware.LoggingMiddleware(router),
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Fatal(server.ListenAndServe())
|
log.Fatal(server.ListenAndServe())
|
||||||
|
15
middleware/logging.go
Normal file
15
middleware/logging.go
Normal 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)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user