1
0
Bifurcation 0

feat: hide logs behind ENV!=production

Cette révision appartient à :
Hayden Young 2021-03-21 20:55:54 +00:00
Parent 5cd05ba871
révision 953f560e98

Voir le fichier

@ -3,14 +3,19 @@ package middlewares
import (
"log"
"net/http"
"os"
"time"
)
func LogMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
now := time.Now()
next.ServeHTTP(w, r)
since := time.Since(now).Milliseconds
log.Printf("%v %v -- %v", r.Method, r.URL.Path, since())
if os.Getenv("ENV") != "production" {
now := time.Now()
next.ServeHTTP(w, r)
since := time.Since(now).Milliseconds
log.Printf("%v %v -- %v", r.Method, r.URL.Path, since())
} else {
next.ServeHTTP(w, r)
}
})
}