/
simple.go
54 lines (42 loc) · 1.04 KB
/
simple.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package timeRoundedCounter
import (
"time"
)
func NewSimple(name string, round time.Duration, capacity int) *SimpleCounter {
c := &SimpleCounter{}
c.base = doNew(name, round, capacity, func() CounterItem { return &simpleCountItem{} })
registerNamedCounter(c)
return c
}
func (this *SimpleCounter) ItemProperties() []string {
return []string{"Count"}
}
func (this *SimpleCounter) Add(n int, t ...time.Time) {
this.base.Add(func(a CounterItem) {
a.(*simpleCountItem).cnt += n
}, t...)
}
func (this *SimpleCounter) GetAll(rtrimZero ...bool) []CounterItem {
return this.base.GetAll(rtrimZero...)
}
type SimpleCounter struct {
base *CustomCounter
}
func (this *SimpleCounter) Name() string {
return this.base.name
}
func (this *SimpleCounter) Round() time.Duration {
return this.base.round
}
type simpleCountItem struct {
cnt int
}
func (this *simpleCountItem) IsZero() bool {
return this.cnt == 0
}
func (this *simpleCountItem) Reset() {
this.cnt = 0
}
func (this *simpleCountItem) Values() []interface{} {
return []interface{}{this.cnt}
}