[#125] ir: Use internal/common/config for reading config

Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
Anton Nikiforov 2023-04-20 14:19:48 +03:00
parent ef222e2487
commit 563780057d

View file

@ -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) {