added glob matching to auth middleware

This commit is contained in:
2026-02-01 19:55:04 +11:00
parent cd29f11296
commit 95a17597cf
5 changed files with 41 additions and 5 deletions

View File

@@ -3,6 +3,8 @@ package hwsauth
import (
"fmt"
"net/url"
"github.com/gobwas/glob"
)
// IgnorePaths excludes specified paths from authentication middleware.
@@ -25,6 +27,19 @@ func (auth *Authenticator[T, TX]) IgnorePaths(paths ...string) error {
return fmt.Errorf("Invalid path: '%s'", path)
}
}
auth.ignoredPaths = paths
auth.ignoredPaths = prepareGlobs(paths)
return nil
}
func prepareGlobs(paths []string) []glob.Glob {
compiledGlobs := make([]glob.Glob, 0, len(paths))
for _, pattern := range paths {
g, err := glob.Compile(pattern)
if err != nil {
// If pattern fails to compile, skip it
continue
}
compiledGlobs = append(compiledGlobs, g)
}
return compiledGlobs
}