Index: filter/count/count.go |
diff --git a/filter/count/count.go b/filter/count/count.go |
index a5478868128be9bcbb3d29e476ffe816e4f14bf6..9206ddcff5cc55a0a16d9eab87a1877cde5e876b 100644 |
--- a/filter/count/count.go |
+++ b/filter/count/count.go |
@@ -9,19 +9,41 @@ |
package count |
import ( |
+ "fmt" |
"sync/atomic" |
) |
+type Counter struct { |
+ value int64 |
+} |
+ |
+func (c *Counter) increment() { |
+ atomic.AddInt64(&c.value, 1) |
iannucci
2015/08/22 01:00:56
as discussed offline, let's just change the curren
|
+} |
+ |
+func (c *Counter) Get() int64 { |
+ return atomic.LoadInt64(&c.value) |
+} |
+ |
// Entry is a success/fail pair for a single API method. It's returned |
// by the Counter interface. |
type Entry struct { |
- Successes int64 |
- Errors int64 |
+ Successes *Counter |
+ Errors *Counter |
+} |
+ |
+func (e *Entry) init() { |
+ e.Successes = &Counter{} |
+ e.Errors = &Counter{} |
+} |
+ |
+func (e *Entry) String() string { |
+ return fmt.Sprintf("{Successes:%d, Errors:%d}", e.Successes.Get(), e.Errors.Get()) |
} |
// Total is a convenience function for getting the total number of calls to |
// this API. It's Successes+Errors. |
-func (e Entry) Total() int64 { return e.Successes + e.Errors } |
+func (e *Entry) Total() int64 { return e.Successes.Get() + e.Errors.Get() } |
func (e *Entry) up(errs ...error) error { |
err := error(nil) |
@@ -29,9 +51,9 @@ func (e *Entry) up(errs ...error) error { |
err = errs[0] |
} |
if err == nil { |
- atomic.AddInt64(&e.Successes, 1) |
+ e.Successes.increment() |
} else { |
- atomic.AddInt64(&e.Errors, 1) |
+ e.Errors.increment() |
} |
return err |
} |