ratelimit

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdaptiveRateLimiter

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

func NewAdaptiveRateLimiter

func NewAdaptiveRateLimiter(backendLimiter RateLimiter, initialRqs int, totalRqs int) *AdaptiveRateLimiter

func (*AdaptiveRateLimiter) AdaptiveLimit

func (r *AdaptiveRateLimiter) AdaptiveLimit() int

func (*AdaptiveRateLimiter) Limit

func (r *AdaptiveRateLimiter) Limit() int

func (*AdaptiveRateLimiter) SetLimit

func (r *AdaptiveRateLimiter) SetLimit(newLimit int) error

func (*AdaptiveRateLimiter) Take

func (r *AdaptiveRateLimiter) Take(ctx context.Context, unit int) error

type BackendError

type BackendError struct {
	Source error
}

func (*BackendError) Error

func (e *BackendError) Error() string

func (*BackendError) Unwrap

func (e *BackendError) Unwrap() error

type InMemoryBackendLimiter

type InMemoryBackendLimiter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

InMemoryBackendLimiter is only for testing/unit test purpose

func NewInMemoryBackendLimiter

func NewInMemoryBackendLimiter(tid tenant.Id, rqs int) *InMemoryBackendLimiter

func (*InMemoryBackendLimiter) Limit

func (r *InMemoryBackendLimiter) Limit() int

func (*InMemoryBackendLimiter) SetLimit

func (r *InMemoryBackendLimiter) SetLimit(newLimit int) error

func (*InMemoryBackendLimiter) Take

func (r *InMemoryBackendLimiter) Take(ctx context.Context, unit int) error

type InvalidUnitError

type InvalidUnitError struct {
	BadUnit int
}

func (*InvalidUnitError) Error

func (e *InvalidUnitError) Error() string

type LimitReached

type LimitReached struct {
}

func (*LimitReached) Error

func (e *LimitReached) Error() string

type RateLimiter

type RateLimiter interface {

	//Take given units
	//Returns LimitReached if limit reached
	//Returns InvalidUnitError if unit <= 0 or > the max limit
	Take(ctx context.Context, unit int) error

	//Limit gets the current limit
	Limit() int

	//SetLimit sets the limit. 0 means there is no limit
	//Returns InvalidUnitError if newLimit < 0
	SetLimit(newLimit int) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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