You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
623 B
28 lines
623 B
package counter |
|
|
|
import "sync/atomic" |
|
|
|
var _ Counter = new(gaugeCounter) |
|
|
|
// A value is a thread-safe counter implementation. |
|
type gaugeCounter int64 |
|
|
|
// NewGauge return a guage counter. |
|
func NewGauge() Counter { |
|
return new(gaugeCounter) |
|
} |
|
|
|
// Add method increments the counter by some value and return new value |
|
func (v *gaugeCounter) Add(val int64) { |
|
atomic.AddInt64((*int64)(v), val) |
|
} |
|
|
|
// Value method returns the counter's current value. |
|
func (v *gaugeCounter) Value() int64 { |
|
return atomic.LoadInt64((*int64)(v)) |
|
} |
|
|
|
// Reset reset the counter. |
|
func (v *gaugeCounter) Reset() { |
|
atomic.StoreInt64((*int64)(v), 0) |
|
}
|
|
|