From aa0f078fc2ed36b54fc6136811323d0ccfa2ff4e Mon Sep 17 00:00:00 2001 From: appleboy Date: Sun, 12 Jan 2025 14:07:18 +0800 Subject: [PATCH] refactor: refactor and optimize exclusion handling logic - Preallocate map with the length of extensions in `NewExcludedExtensions` - Use `ExcludedPathesRegexs` type for the result slice in `NewExcludedPathesRegexs` Signed-off-by: appleboy --- options.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/options.go b/options.go index c0953e0..6630acc 100644 --- a/options.go +++ b/options.go @@ -55,7 +55,7 @@ func WithDecompressFn(decompressFn func(c *gin.Context)) Option { type ExcludedExtensions map[string]struct{} func NewExcludedExtensions(extensions []string) ExcludedExtensions { - res := make(ExcludedExtensions) + res := make(ExcludedExtensions, len(extensions)) for _, e := range extensions { res[e] = struct{}{} } @@ -85,7 +85,7 @@ func (e ExcludedPaths) Contains(requestURI string) bool { type ExcludedPathesRegexs []*regexp.Regexp func NewExcludedPathesRegexs(regexs []string) ExcludedPathesRegexs { - result := make([]*regexp.Regexp, len(regexs)) + result := make(ExcludedPathesRegexs, len(regexs)) for i, reg := range regexs { result[i] = regexp.MustCompile(reg) }