From ca7e0d4f783accd81836144ccd2ddcb4fa81b40c Mon Sep 17 00:00:00 2001 From: Patrick Mylund Nielsen Date: Mon, 2 Jan 2012 14:11:17 +0100 Subject: [PATCH] gofmt and redundant 'if it was enabled' --- cache.go | 16 +++++++--------- cache_test.go | 12 ++++++------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/cache.go b/cache.go index 9cb9eae..0473e40 100644 --- a/cache.go +++ b/cache.go @@ -126,8 +126,8 @@ func (c *cache) Set(k string, x interface{}, d time.Duration) { e = &t } c.Items[k] = &Item{ - Object: x, - Expires: expires, + Object: x, + Expires: expires, Expiration: e, } } @@ -235,7 +235,6 @@ func (c *cache) Decrement(k string, n int64) error { return c.Increment(k, n*-1) } - // Deletes an item from the cache. Does nothing if the item does not exist in the cache. func (c *cache) Delete(k string) { c.mu.Lock() @@ -272,7 +271,6 @@ func (i *Item) Expired() bool { return i.Expiration.Before(time.Now()) } - func (j *janitor) Run(c *cache) { j.stop = make(chan bool) tick := time.Tick(j.Interval) @@ -305,8 +303,8 @@ func New(de, ci time.Duration) *Cache { } c := &cache{ DefaultExpiration: de, - Items: map[string]*Item{}, - mu: &sync.Mutex{}, + Items: map[string]*Item{}, + mu: &sync.Mutex{}, } if ci > 0 { j := &janitor{ @@ -316,9 +314,9 @@ func New(de, ci time.Duration) *Cache { go j.Run(c) } // This trick ensures that the janitor goroutine (which--granted it was enabled--is - // running DeleteExpired on c forever, if it was enabled) does not keep the returned C - // object from being garbage collected. When it is garbage collected, the finalizer stops - // the janitor goroutine, after which c is collected. + // running DeleteExpired on c forever) does not keep the returned C object from being + // garbage collected. When it is garbage collected, the finalizer stops the janitor + // goroutine, after which c is collected. C := &Cache{c} if ci > 0 { runtime.SetFinalizer(C, stopJanitor) diff --git a/cache_test.go b/cache_test.go index 471da2f..15936a0 100644 --- a/cache_test.go +++ b/cache_test.go @@ -33,7 +33,7 @@ func TestCache(t *testing.T) { } if x == nil { t.Error("x for a is nil") - } else if a2 := x.(int); a2 + 2 != 3 { + } else if a2 := x.(int); a2+2 != 3 { t.Error("a2 (which should be 1) plus 2 does not equal 3; value:", a2) } @@ -43,7 +43,7 @@ func TestCache(t *testing.T) { } if x == nil { t.Error("x for b is nil") - } else if b2 := x.(string); b2 + "B" != "bB" { + } else if b2 := x.(string); b2+"B" != "bB" { t.Error("b2 (which should be b) plus B does not equal bB; value:", b2) } @@ -53,7 +53,7 @@ func TestCache(t *testing.T) { } if x == nil { t.Error("x for c is nil") - } else if c2 := x.(float64); c2 + 1.2 != 4.7 { + } else if c2 := x.(float64); c2+1.2 != 4.7 { t.Error("c2 (which should be 3.5) plus 1.2 does not equal 4.7; value:", c2) } } @@ -67,13 +67,13 @@ func TestCacheTimes(t *testing.T) { tc.Set("c", 3, 20*time.Millisecond) tc.Set("d", 4, 70*time.Millisecond) - <-time.After(25*time.Millisecond) + <-time.After(25 * time.Millisecond) _, found = tc.Get("c") if found { t.Error("Found c when it should have been automatically deleted") } - <-time.After(30*time.Millisecond) + <-time.After(30 * time.Millisecond) _, found = tc.Get("a") if found { t.Error("Found a when it should have been automatically deleted") @@ -89,7 +89,7 @@ func TestCacheTimes(t *testing.T) { t.Error("Did not find d even though it was set to expire later than the default") } - <-time.After(20*time.Millisecond) + <-time.After(20 * time.Millisecond) _, found = tc.Get("d") if found { t.Error("Found d when it should have been automatically deleted (later than the default)")