From 11e3306ab5e56770842cae746959acd115439b4b Mon Sep 17 00:00:00 2001 From: Francesco Cosentino Date: Sun, 15 Jan 2023 10:31:36 +0100 Subject: [PATCH] added comments to the exported default middleware methods --- middleware/logging.go | 15 ++++++++------- middleware/stats.go | 21 +++++++++++---------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/middleware/logging.go b/middleware/logging.go index 2f3335c..79cf09e 100644 --- a/middleware/logging.go +++ b/middleware/logging.go @@ -67,7 +67,7 @@ func (mw LoggingMiddleware) GetMultiple(keys ...string) (result map[string]any, return mw.next.GetMultiple(keys...) } -// List +// List logs the time it takes to execute the next middleware. func (mw LoggingMiddleware) List(filters ...any) ([]*models.Item, error) { defer func(begin time.Time) { mw.logger.Infof("method List took: %s", time.Since(begin)) @@ -77,7 +77,7 @@ func (mw LoggingMiddleware) List(filters ...any) ([]*models.Item, error) { return mw.next.List(filters...) } -// Remove +// Remove logs the time it takes to execute the next middleware. func (mw LoggingMiddleware) Remove(keys ...string) { defer func(begin time.Time) { mw.logger.Infof("method Remove took: %s", time.Since(begin)) @@ -87,7 +87,7 @@ func (mw LoggingMiddleware) Remove(keys ...string) { mw.next.Remove(keys...) } -// Clear +// Clear logs the time it takes to execute the next middleware. func (mw LoggingMiddleware) Clear() error { defer func(begin time.Time) { mw.logger.Infof("method Clear took: %s", time.Since(begin)) @@ -97,16 +97,17 @@ func (mw LoggingMiddleware) Clear() error { return mw.next.Clear() } -// Capacity +// Capacity logs the time it takes to execute the next middleware. func (mw LoggingMiddleware) Capacity() int { return mw.next.Capacity() } -// Size +// Size logs the time it takes to execute the next middleware. func (mw LoggingMiddleware) Size() int { return mw.next.Size() } +// TriggerEviction logs the time it takes to execute the next middleware. func (mw LoggingMiddleware) TriggerEviction() { defer func(begin time.Time) { mw.logger.Infof("method TriggerEviction took: %s", time.Since(begin)) @@ -116,7 +117,7 @@ func (mw LoggingMiddleware) TriggerEviction() { mw.next.TriggerEviction() } -// Stop +// Stop logs the time it takes to execute the next middleware. func (mw LoggingMiddleware) Stop() { defer func(begin time.Time) { mw.logger.Infof("method Stop took: %s", time.Since(begin)) @@ -126,7 +127,7 @@ func (mw LoggingMiddleware) Stop() { mw.next.Stop() } -// GetStats +// GetStats logs the time it takes to execute the next middleware. func (mw LoggingMiddleware) GetStats() stats.Stats { defer func(begin time.Time) { mw.logger.Infof("method GetStats took: %s", time.Since(begin)) diff --git a/middleware/stats.go b/middleware/stats.go index 2f8b530..6946b38 100644 --- a/middleware/stats.go +++ b/middleware/stats.go @@ -30,7 +30,7 @@ func (mw StatsCollectorMiddleware) Get(key string) (interface{}, bool) { return mw.next.Get(key) } -// Set +// Set collects stats for the Set method. func (mw StatsCollectorMiddleware) Set(key string, value any, expiration time.Duration) error { start := time.Now() defer func() { @@ -40,7 +40,7 @@ func (mw StatsCollectorMiddleware) Set(key string, value any, expiration time.Du return mw.next.Set(key, value, expiration) } -// GetOrSet +// GetOrSet collects stats for the GetOrSet method. func (mw StatsCollectorMiddleware) GetOrSet(key string, value any, expiration time.Duration) (any, error) { start := time.Now() defer func() { @@ -50,7 +50,7 @@ func (mw StatsCollectorMiddleware) GetOrSet(key string, value any, expiration ti return mw.next.GetOrSet(key, value, expiration) } -// GetMultiple +// GetMultiple collects stats for the GetMultiple method. func (mw StatsCollectorMiddleware) GetMultiple(keys ...string) (result map[string]any, failed map[string]error) { start := time.Now() defer func() { @@ -60,7 +60,7 @@ func (mw StatsCollectorMiddleware) GetMultiple(keys ...string) (result map[strin return mw.next.GetMultiple(keys...) } -// List +// List collects stats for the List method. func (mw StatsCollectorMiddleware) List(filters ...any) ([]*models.Item, error) { start := time.Now() defer func() { @@ -70,6 +70,7 @@ func (mw StatsCollectorMiddleware) List(filters ...any) ([]*models.Item, error) return mw.next.List(filters...) } +// Remove collects stats for the Remove method. func (mw StatsCollectorMiddleware) Remove(keys ...string) { start := time.Now() defer func() { @@ -79,7 +80,7 @@ func (mw StatsCollectorMiddleware) Remove(keys ...string) { mw.next.Remove(keys...) } -// Clear +// Clear collects stats for the Clear method. func (mw StatsCollectorMiddleware) Clear() error { start := time.Now() defer func() { @@ -89,12 +90,12 @@ func (mw StatsCollectorMiddleware) Clear() error { return mw.next.Clear() } -// Capacity +// Capacity returns the capacity of the cache func (mw StatsCollectorMiddleware) Capacity() int { return mw.next.Capacity() } -// TriggerEviction +// TriggerEviction triggers the eviction of the cache func (mw StatsCollectorMiddleware) TriggerEviction() { start := time.Now() defer func() { @@ -104,12 +105,12 @@ func (mw StatsCollectorMiddleware) TriggerEviction() { mw.next.TriggerEviction() } -// Size +// Size returns the size of the cache func (mw StatsCollectorMiddleware) Size() int { return mw.next.Size() } -// Stop stops the cache +// Stop collects the stats for Stop methods and stops the cache and all its goroutines (if any) func (mw StatsCollectorMiddleware) Stop() { start := time.Now() defer func() { @@ -119,7 +120,7 @@ func (mw StatsCollectorMiddleware) Stop() { mw.next.Stop() } -// GetStats +// GetStats returns the stats of the cache func (mw StatsCollectorMiddleware) GetStats() stats.Stats { return mw.next.GetStats() }