diff --git a/httprate.go b/httprate.go index 96ff4bf..75a438d 100644 --- a/httprate.go +++ b/httprate.go @@ -35,6 +35,12 @@ func LimitByRealIP(requestLimit int, windowLength time.Duration) func(next http. return Limit(requestLimit, windowLength, WithKeyFuncs(KeyByRealIP)) } +func Key(key string) func(r *http.Request) (string, error) { + return func(r *http.Request) (string, error) { + return key, nil + } +} + func KeyByIP(r *http.Request) (string, error) { ip, _, err := net.SplitHostPort(r.RemoteAddr) if err != nil { diff --git a/limiter.go b/limiter.go index dc69002..d5ef436 100644 --- a/limiter.go +++ b/limiter.go @@ -33,9 +33,7 @@ func NewRateLimiter(requestLimit int, windowLength time.Duration, options ...Opt } if rl.keyFn == nil { - rl.keyFn = func(r *http.Request) (string, error) { - return "*", nil - } + rl.keyFn = Key("*") } if rl.limitCounter == nil {