ratelimiter

package
v0.1.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Redis node connection details.
	Endpoint string // Required.
	Password string

	// What is the time unit for the ratelimiter.
	// For example, time.Second would limit operations on
	// per-second basis. Duration is a required field.
	Duration time.Duration
}

Config describes a Redis based rate limiter.

type RateLimiter

type RateLimiter interface {
	// Limit decides whether an operation signified by key should
	// be limited or not, based on max operation allowed.
	Limit(ctx context.Context, key string, max int64) (bool, error)
}

RateLimiter is the interface that wraps the Limit method.

A RateLimiter implementation helps limit a given operation, by keeping track of calls made to Limit.

func NewRateLimiter

func NewRateLimiter(ctx context.Context, conf *Config) (RateLimiter, error)

NewRateLimiter returns an AWS ElastiCache Redis based implementation of RateLimiter.

Jump to

Keyboard shortcuts

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