gauge.go 623 B

12345678910111213141516171819202122232425262728
  1. package counter
  2. import "sync/atomic"
  3. var _ Counter = new(gaugeCounter)
  4. // A value is a thread-safe counter implementation.
  5. type gaugeCounter int64
  6. // NewGauge return a guage counter.
  7. func NewGauge() Counter {
  8. return new(gaugeCounter)
  9. }
  10. // Add method increments the counter by some value and return new value
  11. func (v *gaugeCounter) Add(val int64) {
  12. atomic.AddInt64((*int64)(v), val)
  13. }
  14. // Value method returns the counter's current value.
  15. func (v *gaugeCounter) Value() int64 {
  16. return atomic.LoadInt64((*int64)(v))
  17. }
  18. // Reset reset the counter.
  19. func (v *gaugeCounter) Reset() {
  20. atomic.StoreInt64((*int64)(v), 0)
  21. }