naive implementation of caddy like route rules, dependencies upgrade

This commit is contained in:
yusing
2025-01-08 07:18:09 +08:00
parent 1b40f81fcc
commit 35c0463829
9 changed files with 577 additions and 15 deletions

View File

@@ -0,0 +1,28 @@
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)
}