vendor: Mega update all dependencies
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4080
This commit is contained in:
27
vendor/github.com/rcrowley/go-metrics/registry.go
generated
vendored
27
vendor/github.com/rcrowley/go-metrics/registry.go
generated
vendored
@@ -3,6 +3,7 @@ package metrics
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@@ -166,12 +167,34 @@ func NewPrefixedChildRegistry(parent Registry, prefix string) Registry {
|
||||
|
||||
// Call the given function for each registered metric.
|
||||
func (r *PrefixedRegistry) Each(fn func(string, interface{})) {
|
||||
r.underlying.Each(fn)
|
||||
wrappedFn := func(prefix string) func(string, interface{}) {
|
||||
return func(name string, iface interface{}) {
|
||||
if strings.HasPrefix(name, prefix) {
|
||||
fn(name, iface)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
baseRegistry, prefix := findPrefix(r, "")
|
||||
baseRegistry.Each(wrappedFn(prefix))
|
||||
}
|
||||
|
||||
func findPrefix(registry Registry, prefix string) (Registry, string) {
|
||||
switch r := registry.(type) {
|
||||
case *PrefixedRegistry:
|
||||
return findPrefix(r.underlying, r.prefix+prefix)
|
||||
case *StandardRegistry:
|
||||
return r, prefix
|
||||
}
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
// Get the metric by the given name or nil if none is registered.
|
||||
func (r *PrefixedRegistry) Get(name string) interface{} {
|
||||
return r.underlying.Get(name)
|
||||
realName := r.prefix + name
|
||||
return r.underlying.Get(realName)
|
||||
}
|
||||
|
||||
// Gets an existing metric or registers the given one.
|
||||
|
||||
Reference in New Issue
Block a user