added glob matching for ignored paths in hws

This commit is contained in:
2026-02-01 19:42:50 +11:00
parent 7ed40c7afe
commit cd29f11296
13 changed files with 833 additions and 11 deletions

View File

@@ -2,8 +2,9 @@ package hws
import (
"net/http"
"slices"
"time"
"github.com/gobwas/glob"
)
// Middleware to add logs to console with details of the request
@@ -13,7 +14,7 @@ func logging(next http.Handler, logger *logger) http.Handler {
next.ServeHTTP(w, r)
return
}
if slices.Contains(logger.ignoredPaths, r.URL.Path) {
if globTest(r.URL.Path, logger.ignoredPaths) {
next.ServeHTTP(w, r)
return
}
@@ -36,3 +37,12 @@ func logging(next http.Handler, logger *logger) http.Handler {
Msg("Served")
})
}
func globTest(testPath string, globs []glob.Glob) bool {
for _, g := range globs {
if g.Match(testPath) {
return true
}
}
return false
}