diff --git a/collector.go b/collector.go index a67986f..c16d121 100644 --- a/collector.go +++ b/collector.go @@ -23,7 +23,7 @@ func (c *client) RegisterCollector(rc RegisterCollectorFunc) { }) } -var colOnceMap sync.Map +var colOnce sync.Once var col = &collector{ delayLengthDesc: prometheus.NewDesc( prometheus.BuildFQName(namespace, "delay", "queue_length"), @@ -40,8 +40,7 @@ type collector struct { func registerCollector(rc RegisterCollectorFunc, c *client) { col.cs.Store(c, struct{}{}) - m, _ := colOnceMap.LoadOrStore(rc, &sync.Once{}) - m.(*sync.Once).Do(func() { + colOnce.Do(func() { rc(col) }) } diff --git a/metric.go b/metric.go index ce0ddc6..906a94d 100644 --- a/metric.go +++ b/metric.go @@ -17,7 +17,7 @@ const ( ) var ( - metricOnceMap sync.Map + metricOnce sync.Once metric *prometheus.SummaryVec errMetric, hitsMetric, missMetric *prometheus.CounterVec delayPollErrorMetric, delayReclaimErrorMetric, delayReclaimCountMetric *prometheus.CounterVec @@ -55,8 +55,7 @@ func init() { } func registerMetric(rc RegisterCollectorFunc) { - m, _ := metricOnceMap.LoadOrStore(rc, &sync.Once{}) - m.(*sync.Once).Do(func() { + metricOnce.Do(func() { rc(errMetric) rc(hitsMetric) rc(missMetric)