mirror of https://github.com/spf13/viper.git
Add custom metrics for viper.Get calls
This commit is contained in:
parent
e34fb51dd7
commit
f026d8b814
9
viper.go
9
viper.go
|
@ -214,6 +214,7 @@ type Viper struct {
|
||||||
properties *properties.Properties
|
properties *properties.Properties
|
||||||
|
|
||||||
onConfigChange func(fsnotify.Event)
|
onConfigChange func(fsnotify.Event)
|
||||||
|
onGetCallMetric func(key string, value interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns an initialized Viper instance.
|
// New returns an initialized Viper instance.
|
||||||
|
@ -537,6 +538,11 @@ func (v *Viper) AddSecureRemoteProvider(provider, endpoint, path, secretkeyring
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AddGetMetric(getCallMetric func(key string, val interface{})) { v.AddGetMetric(getCallMetric) }
|
||||||
|
func (v *Viper) AddGetMetric(getCallMetric func(key string, val interface{})) {
|
||||||
|
v.onGetCallMetric = getCallMetric
|
||||||
|
}
|
||||||
|
|
||||||
func (v *Viper) providerPathExists(p *defaultRemoteProvider) bool {
|
func (v *Viper) providerPathExists(p *defaultRemoteProvider) bool {
|
||||||
for _, y := range v.remoteProviders {
|
for _, y := range v.remoteProviders {
|
||||||
if reflect.DeepEqual(y, p) {
|
if reflect.DeepEqual(y, p) {
|
||||||
|
@ -726,6 +732,9 @@ func Get(key string) interface{} { return v.Get(key) }
|
||||||
func (v *Viper) Get(key string) interface{} {
|
func (v *Viper) Get(key string) interface{} {
|
||||||
lcaseKey := strings.ToLower(key)
|
lcaseKey := strings.ToLower(key)
|
||||||
val := v.find(lcaseKey, true)
|
val := v.find(lcaseKey, true)
|
||||||
|
if v.onGetCallMetric != nil {
|
||||||
|
v.onGetCallMetric(key, val)
|
||||||
|
}
|
||||||
if val == nil {
|
if val == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue