Skip to content

Commit

Permalink
Add leftmost wildcard support to descriptor values
Browse files Browse the repository at this point in the history
Signed-off-by: Luki Boras <[email protected]>
  • Loading branch information
lukipro committed Nov 15, 2023
1 parent 5e1be59 commit 1ff9529
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/config/config_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ func (this *rateLimitDescriptor) loadDescriptors(config RateLimitConfigToLoad, p
newDescriptor.loadDescriptors(config, newParentKey+".", descriptorConfig.Descriptors, statsManager)
this.descriptors[finalKey] = newDescriptor

// Preload keys ending with "*" symbol.
if finalKey[len(finalKey)-1:] == "*" {
// Preload keys starting or ending with "*" symbol.
if strings.HasPrefix(finalKey, "*") || strings.HasSuffix(finalKey, "*") {
this.wildcardKeys = append(this.wildcardKeys, finalKey)
}
}
Expand Down Expand Up @@ -315,6 +315,10 @@ func (this *rateLimitConfigImpl) GetLimit(

if nextDescriptor == nil && len(prevDescriptor.wildcardKeys) > 0 {
for _, wildcardKey := range prevDescriptor.wildcardKeys {
if strings.HasSuffix(finalKey, strings.TrimPrefix(wildcardKey, "*")) {
nextDescriptor = descriptorsMap[wildcardKey]
break
}
if strings.HasPrefix(finalKey, strings.TrimSuffix(wildcardKey, "*")) {
nextDescriptor = descriptorsMap[wildcardKey]
break
Expand Down

0 comments on commit 1ff9529

Please sign in to comment.