feat(rules): compile path rules directly to glob

This commit is contained in:
yusing
2025-05-05 14:42:55 +08:00
parent 6dd849f480
commit 75db09b1f3
3 changed files with 21 additions and 32 deletions

View File

@@ -1,28 +0,0 @@
package strutils
import (
"sync"
"github.com/gobwas/glob"
)
var (
globPatterns = make(map[string]glob.Glob)
globPatternsMu sync.Mutex
)
func GlobMatch(pattern string, s string) bool {
if glob, ok := globPatterns[pattern]; ok {
return glob.Match(s)
}
globPatternsMu.Lock()
defer globPatternsMu.Unlock()
glob, err := glob.Compile(pattern)
if err != nil {
return false
}
globPatterns[pattern] = glob
return glob.Match(s)
}