updated vendor
This commit is contained in:
+32
-2
@@ -1,14 +1,28 @@
|
||||
package restful
|
||||
|
||||
// Copyright 2025 Ernest Micklei. All rights reserved.
|
||||
// Use of this source code is governed by a license
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
customVerbReg = regexp.MustCompile(":([A-Za-z]+)$")
|
||||
customVerbReg = regexp.MustCompile(":([A-Za-z]+)$")
|
||||
customVerbCache sync.Map // Cache for compiled custom verb regexes
|
||||
customVerbCacheEnabled = true // Enable/disable custom verb regex caching
|
||||
)
|
||||
|
||||
// SetCustomVerbCacheEnabled enables or disables custom verb regex caching.
|
||||
// When disabled, custom verb regex patterns will be compiled on every request.
|
||||
// When enabled (default), compiled custom verb regex patterns are cached for better performance.
|
||||
func SetCustomVerbCacheEnabled(enabled bool) {
|
||||
customVerbCacheEnabled = enabled
|
||||
}
|
||||
|
||||
func hasCustomVerb(routeToken string) bool {
|
||||
return customVerbReg.MatchString(routeToken)
|
||||
}
|
||||
@@ -20,7 +34,23 @@ func isMatchCustomVerb(routeToken string, pathToken string) bool {
|
||||
}
|
||||
|
||||
customVerb := rs[1]
|
||||
specificVerbReg := regexp.MustCompile(fmt.Sprintf(":%s$", customVerb))
|
||||
regexPattern := fmt.Sprintf(":%s$", customVerb)
|
||||
|
||||
// Check cache first (if enabled)
|
||||
if customVerbCacheEnabled {
|
||||
if specificVerbReg, found := getCachedRegexp(&customVerbCache, regexPattern); found {
|
||||
return specificVerbReg.MatchString(pathToken)
|
||||
}
|
||||
}
|
||||
|
||||
// Compile the regex
|
||||
specificVerbReg := regexp.MustCompile(regexPattern)
|
||||
|
||||
// Cache the regex (if enabled)
|
||||
if customVerbCacheEnabled {
|
||||
customVerbCache.Store(regexPattern, specificVerbReg)
|
||||
}
|
||||
|
||||
return specificVerbReg.MatchString(pathToken)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user