github.com/aaabigfish/gopkg@v1.1.0/stat/counter/gauge.go (about) 1 package counter 2 3 import "sync/atomic" 4 5 var _ Counter = new(gaugeCounter) 6 7 // A value is a thread-safe counter implementation. 8 type gaugeCounter int64 9 10 // NewGauge return a guage counter. 11 func NewGauge() Counter { 12 return new(gaugeCounter) 13 } 14 15 // Add method increments the counter by some value and return new value 16 func (v *gaugeCounter) Add(val int64) { 17 atomic.AddInt64((*int64)(v), val) 18 } 19 20 // Value method returns the counter's current value. 21 func (v *gaugeCounter) Value() int64 { 22 return atomic.LoadInt64((*int64)(v)) 23 } 24 25 // Reset reset the counter. 26 func (v *gaugeCounter) Reset() { 27 atomic.StoreInt64((*int64)(v), 0) 28 }