diff --git a/src/limiter/base_limiter.go b/src/limiter/base_limiter.go index c46208e0..a5a3c1be 100644 --- a/src/limiter/base_limiter.go +++ b/src/limiter/base_limiter.go @@ -65,7 +65,7 @@ func (this *BaseRateLimiter) IsOverLimitWithLocalCache(key string) bool { return false } -//Generates response descriptor status based on cache key, over the limit with local cache, over the limit and +// Generates response descriptor status based on cache key, over the limit with local cache, over the limit and // near the limit thresholds. Thresholds are checked in order and are mutually exclusive. func (this *BaseRateLimiter) GetResponseDescriptorStatus(key string, limitInfo *LimitInfo, isOverLimitWithLocalCache bool, hitsAddend uint32) *pb.RateLimitResponse_DescriptorStatus { diff --git a/src/memcached/cache_impl.go b/src/memcached/cache_impl.go index 31b0e4a7..10a87044 100644 --- a/src/memcached/cache_impl.go +++ b/src/memcached/cache_impl.go @@ -72,7 +72,7 @@ func (this *rateLimitMemcacheImpl) DoLimit( continue } - //Check if key is over the limit in local cache + // Check if key is over the limit in local cache. if this.baseRateLimiter.IsOverLimitWithLocalCache(cacheKey.Key) { isOverLimitWithLocalCache[i] = true logger.Debugf("cache key is over the limit: %s", cacheKey.Key) @@ -140,7 +140,7 @@ func (this *rateLimitMemcacheImpl) increaseAsync(cacheKeys []limiter.CacheKey, i expirationSeconds += this.jitterRand.Int63n(this.expirationJitterMaxSeconds) } - // Need to add instead of increment + // Need to add instead of increment. err = this.client.Add(&memcache.Item{ Key: cacheKey.Key, Value: []byte(strconv.FormatUint(hitsAddend, 10)), diff --git a/src/redis/fixed_cache_impl.go b/src/redis/fixed_cache_impl.go index d3fc968b..bd2502ac 100644 --- a/src/redis/fixed_cache_impl.go +++ b/src/redis/fixed_cache_impl.go @@ -50,7 +50,7 @@ func (this *fixedRateLimitCacheImpl) DoLimit( continue } - //Check if key is over the limit in local cache + // Check if key is over the limit in local cache. if this.baseRateLimiter.IsOverLimitWithLocalCache(cacheKey.Key) { isOverLimitWithLocalCache[i] = true logger.Debugf("cache key is over the limit: %s", cacheKey.Key) diff --git a/test/limiter/base_limiter_test.go b/test/limiter/base_limiter_test.go index d90e77b9..0694ca00 100644 --- a/test/limiter/base_limiter_test.go +++ b/test/limiter/base_limiter_test.go @@ -39,7 +39,7 @@ func TestOverLimitWithLocalCache(t *testing.T) { localCache := freecache.NewCache(100) localCache.Set([]byte("key"), []byte("value"), 100) baseRateLimit := limiter.NewBaseRateLimit(nil, nil, 3600, localCache, 0.8) - //returns true, as local cache contains over limit value for the key + // Returns true, as local cache contains over limit value for the key. assert.Equal(true, baseRateLimit.IsOverLimitWithLocalCache("key")) } @@ -48,11 +48,11 @@ func TestNoOverLimitWithLocalCache(t *testing.T) { controller := gomock.NewController(t) defer controller.Finish() baseRateLimit := limiter.NewBaseRateLimit(nil, nil, 3600, nil, 0.8) - //returns false, as local cache is nil + // Returns false, as local cache is nil. assert.Equal(false, baseRateLimit.IsOverLimitWithLocalCache("domain_key_value_1234")) localCache := freecache.NewCache(100) baseRateLimitWithLocalCache := limiter.NewBaseRateLimit(nil, nil, 3600, localCache, 0.8) - //returns false, as local cache does not contain value for cache key + // Returns false, as local cache does not contain value for cache key. assert.Equal(false, baseRateLimitWithLocalCache.IsOverLimitWithLocalCache("domain_key_value_1234")) } @@ -76,7 +76,7 @@ func TestGetResponseStatusOverLimitWithLocalCache(t *testing.T) { baseRateLimit := limiter.NewBaseRateLimit(timeSource, nil, 3600, nil, 0.8) limits := []*config.RateLimit{config.NewRateLimit(5, pb.RateLimitResponse_RateLimit_SECOND, "key_value", statsStore)} limitInfo := limiter.NewRateLimitInfo(limits[0], 2, 6, 4, 5) - //as `isOverLimitWithLocalCache` is passed as `true`, immediate response is returned with no checks of the limits + // As `isOverLimitWithLocalCache` is passed as `true`, immediate response is returned with no checks of the limits. responseStatus := baseRateLimit.GetResponseDescriptorStatus("key", limitInfo, true, 2) assert.Equal(pb.RateLimitResponse_OVER_LIMIT, responseStatus.GetCode()) assert.Equal(uint32(0), responseStatus.GetLimitRemaining()) @@ -101,7 +101,7 @@ func TestGetResponseStatusOverLimit(t *testing.T) { assert.Equal(uint32(0), responseStatus.GetLimitRemaining()) assert.Equal(limits[0].Limit, responseStatus.GetCurrentLimit()) result, _ := localCache.Get([]byte("key")) - //local cache should have been populated with over the limit key + // Local cache should have been populated with over the limit key. assert.Equal("", string(result)) assert.Equal(uint64(2), limits[0].Stats.OverLimit.Value()) assert.Equal(uint64(1), limits[0].Stats.NearLimit.Value())