ratelimiter

package
v2.7.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package ratelimiter implements a rate limiter.

Index

Constants

View Source
const (
	// Kind is the kind of RateLimiter.
	Kind = "RateLimiter"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Policy

type Policy struct {
	Name               string `json:"name" jsonschema:"required"`
	TimeoutDuration    string `json:"timeoutDuration,omitempty" jsonschema:"format=duration"`
	LimitRefreshPeriod string `json:"limitRefreshPeriod,omitempty" jsonschema:"format=duration"`
	LimitForPeriod     int    `json:"limitForPeriod,omitempty" jsonschema:"minimum=1"`
}

Policy defines the policy of a rate limiter

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter defines the rate limiter

func (*RateLimiter) Close

func (rl *RateLimiter) Close()

Close closes RateLimiter.

func (*RateLimiter) Handle

func (rl *RateLimiter) Handle(ctx *context.Context) string

Handle handles HTTP request

func (*RateLimiter) Inherit

func (rl *RateLimiter) Inherit(previousGeneration filters.Filter)

Inherit inherits previous generation of RateLimiter.

func (*RateLimiter) Init

func (rl *RateLimiter) Init()

Init initializes RateLimiter.

func (*RateLimiter) Kind

func (rl *RateLimiter) Kind() *filters.Kind

Kind returns the kind of RateLimiter.

func (*RateLimiter) Name

func (rl *RateLimiter) Name() string

Name returns the name of the RateLimiter filter instance.

func (*RateLimiter) Spec

func (rl *RateLimiter) Spec() filters.Spec

Spec returns the spec used by the RateLimiter

func (*RateLimiter) Status

func (rl *RateLimiter) Status() interface{}

Status returns Status generated by Runtime.

type Rule

type Rule struct {
	Policies         []*Policy  `json:"policies" jsonschema:"required"`
	DefaultPolicyRef string     `json:"defaultPolicyRef,omitempty"`
	URLs             []*URLRule `json:"urls" jsonschema:"required"`
}

Rule is the detailed config of RateLimiter.

type Spec

type Spec struct {
	filters.BaseSpec `json:",inline"`
	Rule             `json:",inline"`
}

Spec is the configuration of a rate limiter

func (Spec) Validate

func (spec Spec) Validate() error

Validate implements custom validation for Spec

type URLRule

type URLRule struct {
	urlrule.URLRule `json:",inline"`
	// contains filtered or unexported fields
}

URLRule defines the rate limiter rule for a URL pattern

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL