Skip to content

Commit

Permalink
rename whitelist to be skiplist
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed Mar 28, 2022
1 parent a222376 commit e6e368b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
22 changes: 11 additions & 11 deletions limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
}
8 changes: 4 additions & 4 deletions whitelist.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit e6e368b

Please sign in to comment.