Index: filter/count/count.go |
diff --git a/filter/count/count.go b/filter/count/count.go |
index a5478868128be9bcbb3d29e476ffe816e4f14bf6..6eae98f5be31b07474007bf384670209b08915bd 100644 |
--- a/filter/count/count.go |
+++ b/filter/count/count.go |
@@ -9,19 +9,36 @@ |
package count |
import ( |
+ "fmt" |
"sync/atomic" |
) |
+type Counter struct { |
+ value int32 |
+} |
+ |
+func (c *Counter) increment() { |
+ atomic.AddInt32(&c.value, 1) |
+} |
+ |
+func (c *Counter) Get() int { |
iannucci
2015/08/22 01:10:51
I don't think Counter is really necessary, though
|
+ return int(atomic.LoadInt32(&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) 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 int64(e.Successes.Get()) + int64(e.Errors.Get()) } |
func (e *Entry) up(errs ...error) error { |
err := error(nil) |
@@ -29,9 +46,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 |
} |