Documentation
¶
Index ¶
- Variables
- type Config
- type RateLimiter
- func (rl *RateLimiter) CASUpdate(ctx context.Context, dataRateKey string, nonce, byt, newByt []byte) ([]byte, error)
- func (rl *RateLimiter) CreateInitialLimit(ctx context.Context, dataRateKey string) ([]byte, error)
- func (rl *RateLimiter) RateLimit(ctx context.Context, dataRateKey string, size int64) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrTooMuchData = errors.New("too much data sent; please retry later")
ErrTooMuchData indicates when too much data has been sent.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Logger for debug and info messages related to rate limiting.
Logger *logrus.Logger
// Maximum burst rate
Cap int64
// Refresh burst tokens over this interval
RefreshInterval time.Duration
// Refresh this amount / interval
RefreshAmount int64
}
Config is the configuration passed to the rate limiter.
type RateLimiter ¶
type RateLimiter struct {
Config
// contains filtered or unexported fields
}
RateLimiter is a simple API to rate limiting with the k/v library.
func NewRateLimiter ¶
func NewRateLimiter(c Config, kvClient *kv.Client) *RateLimiter
NewRateLimiter constructs a new RateLimiter
func (*RateLimiter) CASUpdate ¶
func (rl *RateLimiter) CASUpdate(ctx context.Context, dataRateKey string, nonce, byt, newByt []byte) ([]byte, error)
CASUpdate is a safe method to slam in data. Will return kv.ErrNotEqual if the values do not line up after a few attempts. If unset, it will set the initial value instead of doing the update.
func (*RateLimiter) CreateInitialLimit ¶
CreateInitialLimit creates an initial limit based off the Cap value.
Click to show internal directories.
Click to hide internal directories.