Skip to content

Commit

Permalink
read config only when config file is set
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-zanutto authored Apr 2, 2024
1 parent 46e49fd commit 1edc7bf
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions cmd/greenmask/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,14 @@ func init() {
func initConfig() {
if cfgFile != "" {
viper.SetConfigFile(cfgFile)
if err := viper.ReadInConfig(); err != nil {
log.Fatal().Err(err).Msg("error reading from config file")
}
}

viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()

if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
log.Fatal().Msgf("error parsing config file: %s", err.Error())
}
}

decoderCfg := func(cfg *mapstructure.DecoderConfig) {
cfg.DecodeHook = mapstructure.ComposeDecodeHookFunc(
configUtils.ParamsToByteSliceHookFunc(),
Expand Down

0 comments on commit 1edc7bf

Please sign in to comment.