From 06277513d25f3f6ff309f4f598f73fbba7227f83 Mon Sep 17 00:00:00 2001 From: Vincent Composieux Date: Sat, 19 Oct 2019 10:50:58 +0200 Subject: [PATCH] style: fixed mispelling words and missing comments --- cache/cache.go | 1 + cache/cache_test.go | 2 +- cache/chain.go | 1 + cache/chain_test.go | 4 ++-- cache/loadable.go | 3 ++- cache/loadable_test.go | 4 ++-- cache/metric.go | 1 + metrics/prometheus.go | 4 ++++ store/bigcache.go | 4 +++- store/memcache.go | 4 +++- store/redis.go | 4 +++- store/ristretto.go | 6 ++++-- 12 files changed, 27 insertions(+), 11 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 1924073..28ac52e 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -8,6 +8,7 @@ import ( ) const ( + // CacheType represents the cache type as a string value CacheType = "cache" ) diff --git a/cache/cache_test.go b/cache/cache_test.go index 8113c19..3a10f0d 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -61,7 +61,7 @@ func TestCacheSetWhenErrorOccurs(t *testing.T) { Hello: "world", } - storeErr := errors.New("An error has occured while inserting data into store") + storeErr := errors.New("An error has occurred while inserting data into store") store := &mocksStore.StoreInterface{} store.On("Set", "9b1ac8a6e8ca8ca9477c0a252eb37756", value, options). diff --git a/cache/chain.go b/cache/chain.go index 152743d..a702f8c 100644 --- a/cache/chain.go +++ b/cache/chain.go @@ -8,6 +8,7 @@ import ( ) const ( + // ChainType represents the chain cache type as a string value ChainType = "chain" ) diff --git a/cache/chain_test.go b/cache/chain_test.go index 5c95178..a8da6e9 100644 --- a/cache/chain_test.go +++ b/cache/chain_test.go @@ -141,7 +141,7 @@ func TestChainDeleteWhenError(t *testing.T) { // Given // Cache 1 cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Delete", "my-key").Return(errors.New("An error has occured while deleting key")) + cache1.On("Delete", "my-key").Return(errors.New("An error has occurred while deleting key")) // Cache 2 cache2 := &mocksCache.SetterCacheInterface{} @@ -187,7 +187,7 @@ func TestChainInvalidateWhenError(t *testing.T) { // Cache 1 cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Invalidate", options).Return(errors.New("An unexpected error has occured while invalidation data")) + cache1.On("Invalidate", options).Return(errors.New("An unexpected error has occurred while invalidation data")) // Cache 2 cache2 := &mocksCache.SetterCacheInterface{} diff --git a/cache/loadable.go b/cache/loadable.go index f1e0656..861e91a 100644 --- a/cache/loadable.go +++ b/cache/loadable.go @@ -7,6 +7,7 @@ import ( ) const ( + // LoadableType represents the loadable cache type as a string value LoadableType = "loadable" ) @@ -38,7 +39,7 @@ func (c *LoadableCache) Get(key interface{}) (interface{}, error) { // Unable to find in cache, try to load it from load function object, err = c.loadFunc(key) if err != nil { - log.Printf("An error has occured while trying to load item from load function: %v\n", err) + log.Printf("An error has occurred while trying to load item from load function: %v\n", err) return object, err } diff --git a/cache/loadable_test.go b/cache/loadable_test.go index 7c715f3..ff17685 100644 --- a/cache/loadable_test.go +++ b/cache/loadable_test.go @@ -43,7 +43,7 @@ func TestLoadableGetWhenNotAvailableInLoadFunc(t *testing.T) { cache1.On("Get", "my-key").Return(nil, errors.New("Unable to find in cache 1")) loadFunc := func(key interface{}) (interface{}, error) { - return nil, errors.New("An error has occured while loading data from custom source") + return nil, errors.New("An error has occurred while loading data from custom source") } cache := NewLoadable(loadFunc, cache1) @@ -53,7 +53,7 @@ func TestLoadableGetWhenNotAvailableInLoadFunc(t *testing.T) { // Then assert.Nil(t, value) - assert.Equal(t, errors.New("An error has occured while loading data from custom source"), err) + assert.Equal(t, errors.New("An error has occurred while loading data from custom source"), err) } func TestLoadableGetWhenAvailableInLoadFunc(t *testing.T) { diff --git a/cache/metric.go b/cache/metric.go index d081df5..7cc717a 100644 --- a/cache/metric.go +++ b/cache/metric.go @@ -6,6 +6,7 @@ import ( ) const ( + // MetricType represents the metric cache type as a string value MetricType = "metric" ) diff --git a/metrics/prometheus.go b/metrics/prometheus.go index 470be58..5b6d4ae 100644 --- a/metrics/prometheus.go +++ b/metrics/prometheus.go @@ -13,6 +13,7 @@ var ( cacheCollector *prometheus.GaugeVec = initCacheCollector(namespaceCache) ) +// Prometheus represents the prometheus struct for collecting metrics type Prometheus struct { name string collector *prometheus.GaugeVec @@ -31,14 +32,17 @@ func initCacheCollector(namespace string) *prometheus.GaugeVec { return c } +// NewPrometheus initializes a new prometheus metric instance func NewPrometheus(service string) *Prometheus { return &Prometheus{service, cacheCollector} } +// Record records a metric in prometheus by specyfing the store name, metric name and value func (m *Prometheus) Record(store, metric string, value float64) { m.collector.WithLabelValues(m.name, store, metric).Set(value) } +// RecordFromCodec records metrics in prometheus by retrieving values from a codec instance func (m *Prometheus) RecordFromCodec(codec codec.CodecInterface) { stats := codec.GetStats() storeType := codec.GetStore().GetType() diff --git a/store/bigcache.go b/store/bigcache.go index 4e5ed9f..71c8099 100644 --- a/store/bigcache.go +++ b/store/bigcache.go @@ -15,7 +15,9 @@ type BigcacheClientInterface interface { } const ( - BigcacheType = "bigcache" + // BigcacheType represents the storage type as a string value + BigcacheType = "bigcache" + // BigcacheTagPattern represents the tag pattern to be used as a key in specified storage BigcacheTagPattern = "gocache_tag_%s" ) diff --git a/store/memcache.go b/store/memcache.go index 33b3821..9be97f5 100644 --- a/store/memcache.go +++ b/store/memcache.go @@ -17,7 +17,9 @@ type MemcacheClientInterface interface { } const ( - MemcacheType = "memcache" + // MemcacheType represents the storage type as a string value + MemcacheType = "memcache" + // MemcacheTagPattern represents the tag pattern to be used as a key in specified storage MemcacheTagPattern = "gocache_tag_%s" ) diff --git a/store/redis.go b/store/redis.go index b3b3595..ea7afc6 100644 --- a/store/redis.go +++ b/store/redis.go @@ -16,7 +16,9 @@ type RedisClientInterface interface { } const ( - RedisType = "redis" + // RedisType represents the storage type as a string value + RedisType = "redis" + // RedisTagPattern represents the tag pattern to be used as a key in specified storage RedisTagPattern = "gocache_tag_%s" ) diff --git a/store/ristretto.go b/store/ristretto.go index c20d414..7af1d37 100644 --- a/store/ristretto.go +++ b/store/ristretto.go @@ -8,7 +8,9 @@ import ( ) const ( - RistrettoType = "ristretto" + // RistrettoType represents the storage type as a string value + RistrettoType = "ristretto" + // RistrettoTagPattern represents the tag pattern to be used as a key in specified storage RistrettoTagPattern = "gocache_tag_%s" ) @@ -58,7 +60,7 @@ func (s *RistrettoStore) Set(key interface{}, value interface{}, options *Option } if set := s.client.Set(key, value, options.CostValue()); !set { - err = fmt.Errorf("An error has occured while setting value '%v' on key '%v'", value, key) + err = fmt.Errorf("An error has occurred while setting value '%v' on key '%v'", value, key) } if err != nil {