burning.moe/cmd/web/middleware.go
Lilian Jónsdóttir bedf6cb8e9 actual request logger middleware
instead of log calls in every handler
2024-01-24 23:42:40 -08:00

19 lines
519 B
Go

package main
import (
"net/http"
"github.com/go-chi/chi/v5/middleware"
)
// Middleware is a slice of Middleware (aka func(n http.Handler) http.Handler {})
var Middleware []func(next http.Handler) http.Handler = []func(next http.Handler) http.Handler{
func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
app.Logger.Info("REQUEST", "url", r.URL, "ip", r.RemoteAddr, "useragent", r.UserAgent())
next.ServeHTTP(w, r)
})
},
middleware.Recoverer,
}