From aee1b8ae803a59070d2a4abddf78bad5d88a957b Mon Sep 17 00:00:00 2001 From: Roman Zatonskiy Date: Wed, 12 Jul 2023 11:16:27 +0400 Subject: [PATCH] fixed replace port from env --- prometheus.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/prometheus.go b/prometheus.go index 22bf113..096f597 100644 --- a/prometheus.go +++ b/prometheus.go @@ -121,13 +121,24 @@ func (b *Bundle) providePreRunner( logger *zap.Logger, registry *prometheus.Registry, ) (_ glue.PreRunner, _ func() error, err error) { + // use this hack for UnmarshalKey + // see https://github.com/spf13/viper/issues/188 + var configPath = BundleName + var cfgPath = cfg.Sub(configPath) + if cfgPath != nil { + for _, key := range cfg.Sub(configPath).AllKeys() { + key = configPath + "." + key + cfg.Set(key, cfg.Get(key)) + } + } + var conf = struct { Host string `mapstructure:"host"` Port string `mapstructure:"port"` Path string `mapstructure:"path"` }{} - if err = cfg.UnmarshalKey(BundleName, &conf); err != nil { + if err = cfg.UnmarshalKey(configPath, &conf); err != nil { return nil, nil, err }