iris/middleware/monitor/expvar_uint64.go

34 lines
658 B
Go
Raw Normal View History

2022-02-18 21:19:33 +01:00
package monitor
import (
"expvar"
"strconv"
"sync/atomic"
)
// Uint64 completes the expvar metric interface, holds an uint64 value.
type Uint64 struct {
value uint64
}
// Set sets v to value.
func (v *Uint64) Set(value uint64) {
atomic.StoreUint64(&v.value, value)
}
// Value returns the underline uint64 value.
func (v *Uint64) Value() uint64 {
return atomic.LoadUint64(&v.value)
}
// String returns the text representation of the underline uint64 value.
func (v *Uint64) String() string {
return strconv.FormatUint(atomic.LoadUint64(&v.value), 10)
}
func newUint64(name string) *Uint64 {
v := new(Uint64)
expvar.Publish(name, v)
return v
}