From 563780057d69d320134975e3e1a0664350963783 Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Thu, 20 Apr 2023 14:19:48 +0300 Subject: [PATCH] [#125] ir: Use `internal/common/config` for reading config Signed-off-by: Anton Nikiforov --- cmd/frostfs-ir/defaults.go | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/cmd/frostfs-ir/defaults.go b/cmd/frostfs-ir/defaults.go index 693dd08ee..a3bd867d6 100644 --- a/cmd/frostfs-ir/defaults.go +++ b/cmd/frostfs-ir/defaults.go @@ -1,44 +1,28 @@ package main import ( - "strings" "time" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/config" + configViper "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common/config" "github.com/spf13/viper" ) func newConfig(path, directory string) (*viper.Viper, error) { const envPrefix = "FROSTFS_IR" - var ( - err error - v = viper.New() - ) + var err error + var dv = viper.New() - v.SetEnvPrefix(envPrefix) - v.AutomaticEnv() - v.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) + defaultConfiguration(dv) - defaultConfiguration(v) - - if path != "" { - v.SetConfigFile(path) - if strings.HasSuffix(path, ".json") { - v.SetConfigType("json") - } else { - v.SetConfigType("yml") - } - if err = v.ReadInConfig(); err != nil { - return v, err - } + _, _, err = configViper.CreateViper(configViper.WithConfigFile(path), + configViper.WithConfigDir(directory), configViper.WithEnvPrefix(envPrefix), + configViper.WithViper(dv)) + if err != nil { + return nil, err } - if directory != "" { - err = config.ReadConfigDir(v, directory) - } - - return v, err + return dv, err } func defaultConfiguration(cfg *viper.Viper) {