Selaa lähdekoodia

GetOrRegister for the DefaultRegistry.

Richard Crowley 12 vuotta sitten
vanhempi
commit
569c4a2ce0
1 muutettua tiedostoa jossa 6 lisäystä ja 0 poistoa
  1. 6 0
      registry.go

+ 6 - 0
registry.go

@@ -120,6 +120,12 @@ func Get(name string) interface{} {
 	return DefaultRegistry.Get(name)
 }
 
+// Gets an existing metric or creates and registers a new one. Threadsafe
+// alternative to calling Get and Register on failure.
+func GetOrRegister(name string, i interface{}) interface{} {
+	return DefaultRegistry.GetOrRegister(name, i)
+}
+
 // Register the given metric under the given name.
 func Register(name string, i interface{}) {
 	DefaultRegistry.Register(name, i)