From e6e368b107e03b350e44976986e59dba517dc51c Mon Sep 17 00:00:00 2001 From: Valentin Kuznetsov Date: Mon, 28 Mar 2022 12:05:53 -0400 Subject: [PATCH] rename whitelist to be skiplist --- limiter.go | 22 +++++++++++----------- options.go | 12 ++++++------ whitelist.go | 8 ++++---- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/limiter.go b/limiter.go index 2c883e9..32281a3 100644 --- a/limiter.go +++ b/limiter.go @@ -22,10 +22,10 @@ type Context struct { // Limiter is the limiter instance. type Limiter struct { - Store Store - Rate Rate - Options Options - WhiteList WhiteList + Store Store + Rate Rate + Options Options + SkipList SkipList } // New returns an instance of Limiter. @@ -38,20 +38,20 @@ func New(store Store, rate Rate, options ...Option) *Limiter { for _, o := range options { o(&opt) } - whiteList := WhiteList{ - Keys: opt.WhiteList, + whiteList := SkipList{ + Keys: opt.SkipList, } return &Limiter{ - Store: store, - Rate: rate, - Options: opt, - WhiteList: whiteList, + Store: store, + Rate: rate, + Options: opt, + SkipList: whiteList, } } // Get returns the limit for given identifier. func (limiter *Limiter) Get(ctx context.Context, key string) (Context, error) { - if limiter.WhiteList.HasKey(key) { + if limiter.SkipList.HasKey(key) { return Context{}, nil } return limiter.Store.Get(ctx, key, limiter.Rate) diff --git a/options.go b/options.go index bb493a1..4741002 100644 --- a/options.go +++ b/options.go @@ -25,8 +25,8 @@ type Options struct { // Please read the section "Limiter behind a reverse proxy" in the README for further information. ClientIPHeader string - // WhiteList represents white list of keys which will be skipped by limiter - WhiteList []string + // SkipList represents list of keys which will be skipped by limiter + SkipList []string } // WithIPv4Mask will configure the limiter to use given mask for IPv4 address. @@ -63,12 +63,12 @@ func WithClientIPHeader(header string) Option { } } -// WithWhiteList will configure the limiter to use list of provided +// WithSkipList will configure the limiter to use list of provided // exception keys (which may be IP addresses or custome header values). // This list will be consulted at every request and if key will be found in -// WhiteList the limiter functionality will be skipped for that key. -func WithWhiteList(wlist []string) Option { +// SkipList the limiter functionality will be skipped for that key. +func WithSkipList(wlist []string) Option { return func(o *Options) { - o.WhiteList = wlist + o.SkipList = wlist } } diff --git a/whitelist.go b/whitelist.go index c304804..722ba24 100644 --- a/whitelist.go +++ b/whitelist.go @@ -1,12 +1,12 @@ package limiter -// WhiteList represent white list of keys -type WhiteList struct { +// SkipList represent white list of keys +type SkipList struct { Keys []string } -// HasKey implements basic look-up of given key in WhiteList -func (w *WhiteList) HasKey(key string) bool { +// HasKey implements basic look-up of given key in SkipList +func (w *SkipList) HasKey(key string) bool { for _, k := range w.Keys { if k == key { return true