mirror of
https://github.com/dutchcoders/transfer.sh.git
synced 2024-11-30 08:00:19 +01:00
16 lines
411 B
Go
16 lines
411 B
Go
package ratelimit
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
// TokenBucketStore is an interface for for any storage implementing
|
|
// Token Bucket algorithm.
|
|
type TokenBucketStore interface {
|
|
InitRate(rate int, window time.Duration)
|
|
Take(key string) (taken bool, remaining int, reset time.Time, err error)
|
|
}
|
|
|
|
// KeyFn is a function returning bucket key depending on request data.
|
|
type KeyFn func(r *http.Request) string
|