var _ … type cachedMetrics … // NewCachedMetrics creates a new cachedMetrics wrapping another // MetricsProvider and caching the results. func NewCachedMetrics(provider MetricsProvider) MetricsProvider { … } // GetMetrics runs the wrapped metrics provider's GetMetrics method once and // caches the result. Will not cache result if there is an error. // See MetricsProvider.GetMetrics func (md *cachedMetrics) GetMetrics() (*Metrics, error) { … } type cacheOnce … // Copied from sync.Once but we don't want to cache the results if there is an // error func (o *cacheOnce) cache(f func() error) { … }