You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

17 lines
411 B

  1. package ratelimit
  2. import (
  3. "net/http"
  4. "time"
  5. )
  6. // TokenBucketStore is an interface for for any storage implementing
  7. // Token Bucket algorithm.
  8. type TokenBucketStore interface {
  9. InitRate(rate int, window time.Duration)
  10. Take(key string) (taken bool, remaining int, reset time.Time, err error)
  11. }
  12. // KeyFn is a function returning bucket key depending on request data.
  13. type KeyFn func(r *http.Request) string