MCPcopy
hub / github.com/pocketbase/pocketbase / FindRateLimitRule

Method FindRateLimitRule

core/settings_model.go:617–645  ·  view source on GitHub ↗

FindRateLimitRule returns the first matching rule based on the provided labels. Optionally you can further specify a list of valid RateLimitRule.Audience values to further filter the matching rule (aka. the rule Audience will have to exist in one of the specified options).

(searchLabels []string, optOnlyAudience ...string)

Source from the content-addressed store, hash-verified

615// Optionally you can further specify a list of valid RateLimitRule.Audience values to further filter the matching rule
616// (aka. the rule Audience will have to exist in one of the specified options).
617func (c *RateLimitsConfig) FindRateLimitRule(searchLabels []string, optOnlyAudience ...string) (RateLimitRule, bool) {
618 var prefixRules []int
619
620 for i, label := range searchLabels {
621 // check for direct match
622 for j := range c.Rules {
623 if label == c.Rules[j].Label &&
624 (len(optOnlyAudience) == 0 || slices.Contains(optOnlyAudience, c.Rules[j].Audience)) {
625 return c.Rules[j], true
626 }
627
628 if i == 0 && strings.HasSuffix(c.Rules[j].Label, "/") {
629 prefixRules = append(prefixRules, j)
630 }
631 }
632
633 // check for prefix match
634 if len(prefixRules) > 0 {
635 for j := range prefixRules {
636 if strings.HasPrefix(label+"/", c.Rules[prefixRules[j]].Label) &&
637 (len(optOnlyAudience) == 0 || slices.Contains(optOnlyAudience, c.Rules[prefixRules[j]].Audience)) {
638 return c.Rules[prefixRules[j]], true
639 }
640 }
641 }
642 }
643
644 return RateLimitRule{}, false
645}
646
647// MarshalJSON implements the [json.Marshaler] interface.
648func (c RateLimitsConfig) MarshalJSON() ([]byte, error) {

Callers 3

rateLimitFunction · 0.80
checkCollectionRateLimitFunction · 0.80

Calls

no outgoing calls

Tested by 1