func (m *StandardMetrics) GetOrRegister(name string, i interface{}) interface{} {
	m.mutex.RLock()
	metric, ok := m.metrics[name]
	m.mutex.RUnlock()
	if ok {
		return metric
	}
	m.mutex.Lock()
	defer m.mutex.Unlock()
	if metric, ok := m.metrics[name]; ok {
		return metric
	}
	if v := reflect.ValueOf(i); v.Kind() == reflect.Func {
		i = v.Call(nil)[0].Interface()
	}
	m.register(name, i)
	return i
}
Gets an existing metric or creates and registers a new one. Threadsafe
alternative to calling Get and Register on failure.
The interface can be the metric to register if not found in registry,
or a function returning the metric for lazy instantiation.
package metrics
import (
	"fmt"
	"reflect"
	"sync"
)
type DuplicateMetric string
func (err DuplicateMetric) Error() string {
	return fmt.Sprintf("duplicate metric: %s", string(err))
}
type Metrics interface {
	GetOrRegister(string, interface{}) interface{}
	Unregister(string)
	UnregisterAll()
}
type StandardMetrics struct {
	metrics map[string]interface{}
	mutex   sync.RWMutex
}
func NewMetrics() Metrics {
	return &StandardMetrics{metrics: make(map[string]interface{})}
}