Skip to content

Commit

Permalink
Set limit for arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
canack committed Oct 6, 2024
1 parent 9e3645f commit d901290
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions middleware/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func createExtractors(lookups string, authScheme string) ([]ValuesExtractor, err
return nil, nil
}
sources := strings.Split(lookups, ",")
var extractors = make([]ValuesExtractor, 0)
var extractors = make([]ValuesExtractor, 0, len(sources))
for _, source := range sources {
parts := strings.Split(source, ":")
if len(parts) < 2 {
Expand Down Expand Up @@ -104,7 +104,7 @@ func valuesFromHeader(header string, valuePrefix string) ValuesExtractor {
return nil, errHeaderExtractorValueMissing
}

result := make([]string, 0)
result := make([]string, 0, len(values))
for i, value := range values {
if prefixLen == 0 {
result = append(result, value)
Expand Down Expand Up @@ -147,7 +147,7 @@ func valuesFromQuery(param string) ValuesExtractor {
// valuesFromParam returns a function that extracts values from the url param string.
func valuesFromParam(param string) ValuesExtractor {
return func(c echo.Context) ([]string, error) {
result := make([]string, 0)
result := make([]string, 0, len(c.ParamNames()))
paramVales := c.ParamValues()
for i, p := range c.ParamNames() {
if param == p {
Expand All @@ -172,7 +172,7 @@ func valuesFromCookie(name string) ValuesExtractor {
return nil, errCookieExtractorValueMissing
}

result := make([]string, 0)
result := make([]string, 0, len(cookies))
for i, cookie := range cookies {
if name == cookie.Name {
result = append(result, cookie.Value)
Expand Down

0 comments on commit d901290

Please sign in to comment.