mirror of
https://github.com/securego/gosec.git
synced 2026-05-04 21:17:53 +02:00
89685023f9
* feat: implement global cache usage in rules * refactor: make global cache generic with local key types - Remove GlobalKey struct from gosec_cache.go - Each use case now defines its own key type (type safety via Go's type system) - Move RegexMatchWithCache to separate regex_cache.go file - Move cache kind constants to rules/hardcoded_credentials.go as local types - Add documentation for cache key requirements
22 lines
542 B
Go
22 lines
542 B
Go
package gosec
|
|
|
|
import "regexp"
|
|
|
|
// regexCacheKey is the cache key for regex match results.
|
|
type regexCacheKey struct {
|
|
Re *regexp.Regexp
|
|
Str string
|
|
}
|
|
|
|
// RegexMatchWithCache returns the result of re.MatchString(s), using GlobalCache
|
|
// to store previous results for improved performance on repeated lookups.
|
|
func RegexMatchWithCache(re *regexp.Regexp, s string) bool {
|
|
key := regexCacheKey{Re: re, Str: s}
|
|
if val, ok := GlobalCache.Get(key); ok {
|
|
return val.(bool)
|
|
}
|
|
res := re.MatchString(s)
|
|
GlobalCache.Add(key, res)
|
|
return res
|
|
}
|