mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
return T from GetOrRegister instead of any
This commit is contained in:
parent
d6af162a15
commit
75b3e77eda
10 changed files with 18 additions and 18 deletions
|
|
@ -7,7 +7,7 @@ import (
|
|||
// GetOrRegisterCounter returns an existing Counter or constructs and registers
|
||||
// a new Counter.
|
||||
func GetOrRegisterCounter(name string, r Registry) *Counter {
|
||||
return GetOrRegister(name, NewCounter, r).(*Counter)
|
||||
return GetOrRegister(name, NewCounter, r)
|
||||
}
|
||||
|
||||
// NewCounter constructs a new Counter.
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
// GetOrRegisterCounterFloat64 returns an existing *CounterFloat64 or constructs and registers
|
||||
// a new CounterFloat64.
|
||||
func GetOrRegisterCounterFloat64(name string, r Registry) *CounterFloat64 {
|
||||
return GetOrRegister(name, NewCounterFloat64, r).(*CounterFloat64)
|
||||
return GetOrRegister(name, NewCounterFloat64, r)
|
||||
}
|
||||
|
||||
// NewCounterFloat64 constructs a new CounterFloat64.
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ func (g GaugeSnapshot) Value() int64 { return int64(g) }
|
|||
// GetOrRegisterGauge returns an existing Gauge or constructs and registers a
|
||||
// new Gauge.
|
||||
func GetOrRegisterGauge(name string, r Registry) *Gauge {
|
||||
return GetOrRegister(name, NewGauge, r).(*Gauge)
|
||||
return GetOrRegister(name, NewGauge, r)
|
||||
}
|
||||
|
||||
// NewGauge constructs a new Gauge.
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
// GetOrRegisterGaugeFloat64 returns an existing GaugeFloat64 or constructs and registers a
|
||||
// new GaugeFloat64.
|
||||
func GetOrRegisterGaugeFloat64(name string, r Registry) *GaugeFloat64 {
|
||||
return GetOrRegister(name, NewGaugeFloat64, r).(*GaugeFloat64)
|
||||
return GetOrRegister(name, NewGaugeFloat64, r)
|
||||
}
|
||||
|
||||
// GaugeFloat64Snapshot is a read-only copy of a GaugeFloat64.
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ func (val GaugeInfoValue) String() string {
|
|||
// GetOrRegisterGaugeInfo returns an existing GaugeInfo or constructs and registers a
|
||||
// new GaugeInfo.
|
||||
func GetOrRegisterGaugeInfo(name string, r Registry) *GaugeInfo {
|
||||
return GetOrRegister(name, NewGaugeInfo, r).(*GaugeInfo)
|
||||
return GetOrRegister(name, NewGaugeInfo, r)
|
||||
}
|
||||
|
||||
// NewGaugeInfo constructs a new GaugeInfo.
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
// Be sure to unregister the meter from the registry once it is of no use to
|
||||
// allow for garbage collection.
|
||||
func GetOrRegisterMeter(name string, r Registry) *Meter {
|
||||
return GetOrRegister(name, NewMeter, r).(*Meter)
|
||||
return GetOrRegister(name, NewMeter, r)
|
||||
}
|
||||
|
||||
// NewMeter constructs a new Meter and launches a goroutine.
|
||||
|
|
|
|||
|
|
@ -327,11 +327,11 @@ func Get(name string) interface{} {
|
|||
|
||||
// GetOrRegister gets an existing metric or creates and registers a new one. Threadsafe
|
||||
// alternative to calling Get and Register on failure.
|
||||
func GetOrRegister[T any](name string, ctor func() T, r Registry) interface{} {
|
||||
func GetOrRegister[T any](name string, ctor func() T, r Registry) T {
|
||||
if r == nil {
|
||||
r = DefaultRegistry
|
||||
}
|
||||
return r.GetOrRegister(name, func() any { return ctor() })
|
||||
return r.GetOrRegister(name, func() any { return ctor() }).(T)
|
||||
}
|
||||
|
||||
// Register the given metric under the given name. Returns a ErrDuplicateMetric
|
||||
|
|
|
|||
|
|
@ -98,10 +98,10 @@ func TestRegistryGetOrRegister(t *testing.T) {
|
|||
r := NewRegistry()
|
||||
|
||||
// First metric wins with GetOrRegister
|
||||
_ = GetOrRegister("foo", NewCounter, r)
|
||||
m := GetOrRegister("foo", NewGauge, r)
|
||||
if _, ok := m.(*Counter); !ok {
|
||||
t.Fatal(m)
|
||||
c1 := GetOrRegister("foo", NewCounter, r)
|
||||
c2 := GetOrRegister("foo", NewCounter, r)
|
||||
if c1 != c2 {
|
||||
t.Fatal("counters should've matched")
|
||||
}
|
||||
|
||||
i := 0
|
||||
|
|
@ -123,10 +123,10 @@ func TestRegistryGetOrRegisterWithLazyInstantiation(t *testing.T) {
|
|||
r := NewRegistry()
|
||||
|
||||
// First metric wins with GetOrRegister
|
||||
_ = GetOrRegister("foo", NewCounter, r)
|
||||
m := GetOrRegister("foo", NewGauge, r)
|
||||
if _, ok := m.(*Counter); !ok {
|
||||
t.Fatal(m)
|
||||
c1 := GetOrRegister("foo", NewCounter, r)
|
||||
c2 := GetOrRegister("foo", NewCounter, r)
|
||||
if c1 != c2 {
|
||||
t.Fatal("counters should've matched")
|
||||
}
|
||||
|
||||
i := 0
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
// GetOrRegisterResettingTimer returns an existing ResettingTimer or constructs and registers a
|
||||
// new ResettingTimer.
|
||||
func GetOrRegisterResettingTimer(name string, r Registry) *ResettingTimer {
|
||||
return GetOrRegister(name, NewResettingTimer, r).(*ResettingTimer)
|
||||
return GetOrRegister(name, NewResettingTimer, r)
|
||||
}
|
||||
|
||||
// NewRegisteredResettingTimer constructs and registers a new ResettingTimer.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
// Be sure to unregister the meter from the registry once it is of no use to
|
||||
// allow for garbage collection.
|
||||
func GetOrRegisterTimer(name string, r Registry) *Timer {
|
||||
return GetOrRegister(name, NewTimer, r).(*Timer)
|
||||
return GetOrRegister(name, NewTimer, r)
|
||||
}
|
||||
|
||||
// NewCustomTimer constructs a new Timer from a Histogram and a Meter.
|
||||
|
|
|
|||
Loading…
Reference in a new issue