diff --git a/.golangci.yml b/.golangci.yml index 33598d6..3ee3205 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -75,6 +75,7 @@ linters: - mnd - exportloopref - contextcheck + - intrange # not supported by yaegi issues: exclude-use-default: false max-same-issues: 0 diff --git a/bouncer.go b/bouncer.go index 6b5cf93..78b43da 100644 --- a/bouncer.go +++ b/bouncer.go @@ -330,7 +330,7 @@ func New(_ context.Context, next http.Handler, config *configuration.Config, nam // ServeHTTP principal function of plugin. // -//nolint:nestif +//nolint:nestif,gocognit func (bouncer *Bouncer) ServeHTTP(rw http.ResponseWriter, req *http.Request) { if !bouncer.enabled { bouncer.next.ServeHTTP(rw, req) diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index f223b37..83f8743 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -27,7 +27,7 @@ const ( CacheMiss = "cache:miss" // CacheUnreachable error string when cache is unreachable. CacheUnreachable = "cache:unreachable" - // cidrPrefix store all cidr within the same key + // cidrPrefix store all cidr within the same key. cidrPrefix = "cidr:" ) @@ -149,6 +149,7 @@ func (c *Client) Set(key string, value string, duration int64) { c.cache.set(key, value, duration) } +// DeleteCIDR removes a CIDR decision from the cache. func (c *Client) DeleteCIDR(cidr string) { cidr = ip.NormalizeCIDR(cidr) if cidr == "" { @@ -158,6 +159,7 @@ func (c *Client) DeleteCIDR(cidr string) { c.log.Debug(fmt.Sprintf("cache:DeleteCIDR cidr:%v", cidr)) } +// GetCIDR checks if an IP matches a CIDR decision in the cache. func (c *Client) GetCIDR(ipStr string) (string, error) { keys := ip.CIDRKeys(ipStr) if keys == nil { @@ -172,6 +174,7 @@ func (c *Client) GetCIDR(ipStr string) (string, error) { return "", errors.New(CacheMiss) } +// SetCIDR stores a CIDR decision in the cache. func (c *Client) SetCIDR(cidr, value string, duration int64) { cidr = ip.NormalizeCIDR(cidr) if cidr == "" {