Chromium Code Reviews| Index: go/src/infra/gae/libs/gae/filters/count/count.go |
| diff --git a/go/src/infra/gae/libs/gae/filters/count/count.go b/go/src/infra/gae/libs/gae/filters/count/count.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a5478868128be9bcbb3d29e476ffe816e4f14bf6 |
| --- /dev/null |
| +++ b/go/src/infra/gae/libs/gae/filters/count/count.go |
| @@ -0,0 +1,37 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Package count contains 'counter' filters for all the gae services. This |
| +// serves as a set of simple example filters, and also enables other filters |
| +// to test to see if certain underlying APIs are called when they should be |
| +// (e.g. for the datastore mcache filter, for example). |
| +package count |
| + |
| +import ( |
| + "sync/atomic" |
| +) |
| + |
| +// 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 |
| +} |
| + |
| +// 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) up(errs ...error) error { |
|
nodir
2015/09/19 05:45:50
why do you accept a slice but you use only first e
|
| + err := error(nil) |
| + if len(errs) > 0 { |
| + err = errs[0] |
| + } |
| + if err == nil { |
| + atomic.AddInt64(&e.Successes, 1) |
| + } else { |
| + atomic.AddInt64(&e.Errors, 1) |
| + } |
| + return err |
| +} |