OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Package count contains 'counter' filters for all the gae services. This | 5 // Package count contains 'counter' filters for all the gae services. This |
6 // serves as a set of simple example filters, and also enables other filters | 6 // serves as a set of simple example filters, and also enables other filters |
7 // to test to see if certain underlying APIs are called when they should be | 7 // to test to see if certain underlying APIs are called when they should be |
8 // (e.g. for the datastore mcache filter, for example). | 8 // (e.g. for the datastore mcache filter, for example). |
9 package count | 9 package count |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 } | 33 } |
34 | 34 |
35 func (e *Entry) String() string { | 35 func (e *Entry) String() string { |
36 return fmt.Sprintf("{Successes:%d, Errors:%d}", e.Successes(), e.Errors(
)) | 36 return fmt.Sprintf("{Successes:%d, Errors:%d}", e.Successes(), e.Errors(
)) |
37 } | 37 } |
38 | 38 |
39 // Total is a convenience function for getting the total number of calls to | 39 // Total is a convenience function for getting the total number of calls to |
40 // this API. It's Successes+Errors. | 40 // this API. It's Successes+Errors. |
41 func (e *Entry) Total() int64 { return int64(e.Successes()) + int64(e.Errors())
} | 41 func (e *Entry) Total() int64 { return int64(e.Successes()) + int64(e.Errors())
} |
42 | 42 |
| 43 // Successes returns the number of successful invocations for this Entry. |
43 func (e *Entry) Successes() int { | 44 func (e *Entry) Successes() int { |
44 return e.successes.get() | 45 return e.successes.get() |
45 } | 46 } |
46 | 47 |
| 48 // Errors returns the number of unsuccessful invocations for this Entry. |
47 func (e *Entry) Errors() int { | 49 func (e *Entry) Errors() int { |
48 return e.errors.get() | 50 return e.errors.get() |
49 } | 51 } |
50 | 52 |
51 func (e *Entry) up(errs ...error) error { | 53 func (e *Entry) up(errs ...error) error { |
52 err := error(nil) | 54 err := error(nil) |
53 if len(errs) > 0 { | 55 if len(errs) > 0 { |
54 err = errs[0] | 56 err = errs[0] |
55 } | 57 } |
56 if err == nil { | 58 if err == nil { |
57 e.successes.increment() | 59 e.successes.increment() |
58 } else { | 60 } else { |
59 e.errors.increment() | 61 e.errors.increment() |
60 } | 62 } |
61 return err | 63 return err |
62 } | 64 } |
OLD | NEW |