Added middleware to let excluded files skip middleware chain

This commit is contained in:
2025-02-11 19:37:39 +11:00
parent 750de24fd1
commit 97aabcf06f
6 changed files with 75 additions and 9 deletions

View File

@@ -2,7 +2,6 @@ package middleware
import (
"net/http"
"strings"
"time"
"github.com/rs/zerolog"
@@ -29,13 +28,10 @@ func Logging(logger *zerolog.Logger, next http.Handler) http.Handler {
statusCode: http.StatusOK,
}
next.ServeHTTP(wrapped, r)
if !strings.Contains(r.URL.Path, "favicon.ico") &&
!strings.Contains(r.URL.Path, "output.css") {
logger.Info().
Int("status", wrapped.statusCode).
Str("method", r.Method).
Str("resource", r.URL.Path).
Dur("time_elapsed", time.Since(start)).Msg("Served")
}
logger.Info().
Int("status", wrapped.statusCode).
Str("method", r.Method).
Str("resource", r.URL.Path).
Dur("time_elapsed", time.Since(start)).Msg("Served")
})
}