Skip to content

Commit

Permalink
Merge pull request #3 from Rototot/fixed-configuration-port
Browse files Browse the repository at this point in the history
Fixed grab setting from Viper
  • Loading branch information
snovichkov authored Aug 2, 2023
2 parents 358b353 + aee1b8a commit 5a8fdd0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 5a8fdd0

Please sign in to comment.