Skip to content

Commit

Permalink
refactor: refactor and optimize exclusion handling logic
Browse files Browse the repository at this point in the history
- Preallocate map with the length of extensions in `NewExcludedExtensions`
- Use `ExcludedPathesRegexs` type for the result slice in `NewExcludedPathesRegexs`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Jan 12, 2025
1 parent fa26419 commit aa0f078
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit aa0f078

Please sign in to comment.