ratelimit

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Global

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

func GlobalSemaphore

func GlobalSemaphore(rc *redis.Client, c SemaphoreConfig, name string) *Global

func (*Global) TryAcquire

func (g *Global) TryAcquire(ctx context.Context) (func(), error)

func (*Global) TryAcquireN

func (g *Global) TryAcquireN(ctx context.Context, n int64) (func(), error)

type Local

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

func LocalSemaphore

func LocalSemaphore(c SemaphoreConfig, name string) *Local

func (*Local) TryAcquire

func (l *Local) TryAcquire(ctx context.Context) (func(), error)

func (*Local) TryAcquireN

func (l *Local) TryAcquireN(ctx context.Context, n int64) (func(), error)

type RPM

type RPM interface {
	// StorReq acquires storage api request rate limit based on RPM config.
	StorReq(ctx context.Context, storage string) error
	// StorReqN acquires n storage api requests rate limit based on RPM config.
	StorReqN(ctx context.Context, storage string, n int) error
}

RPM storage rate limit based on requests per minute

type Semaphore

type Semaphore interface {
	// TryAcquire tries to acquire storage resource until work function is done.
	// Returns release function. Also, will be released when ctx cancelled.
	// Returns dom.ErrRateLimitExceeded if resource is not acquired.
	TryAcquire(ctx context.Context) (release func(), err error)
	// TryAcquireN - see TryAcquire
	TryAcquireN(ctx context.Context, n int64) (release func(), err error)
}

Semaphore storage rate limit based on N concurrent resource clients.

type SemaphoreConfig

type SemaphoreConfig struct {
	Enabled  bool          `yaml:"enabled"`
	Limit    int64         `yaml:"limit"`
	RetryMin time.Duration `yaml:"retryMin"`
	RetryMax time.Duration `yaml:"retryMax"`
}

type Svc

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

func New

func New(rc *redis.Client, conf map[string]s3.RateLimit) *Svc

func (*Svc) StorReq

func (s *Svc) StorReq(ctx context.Context, storage string) error

func (*Svc) StorReqN

func (s *Svc) StorReqN(ctx context.Context, storage string, n int) error

Jump to

Keyboard shortcuts

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