rate

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: MIT Imports: 4 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

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

Limiter is a helper tool which allows controlling the number and concurrency of requests made against a generic target.

func NewLimiter

func NewLimiter(
	config *LimiterConfig,
) *Limiter

NewLimiter creates a new rate limiter instance basing on given config.

func (*Limiter) AcquirePermit

func (l *Limiter) AcquirePermit() error

AcquirePermit acquires the permit.

func (*Limiter) ReleasePermit

func (l *Limiter) ReleasePermit()

ReleasePermit releases the permit.

type LimiterConfig

type LimiterConfig struct {
	// RequestsPerSecondLimit sets the maximum average number of requests
	// per second. It's important to note that in short periods of time
	// the actual average may exceed this limit slightly.
	RequestsPerSecondLimit int

	// ConcurrencyLimit sets the maximum number of concurrent requests which
	// can be executed against the target at the same time.
	ConcurrencyLimit int

	// AcquirePermitTimeout determines how long a request can wait trying
	// to acquire a permit from the rate limiter.
	AcquirePermitTimeout time.Duration
}

LimiterConfig represents the configuration of the rate limiter.

Jump to

Keyboard shortcuts

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