forked from TrueCloudLab/frostfs-node
[#125] ir: Use internal/common/config
for reading config
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
ef222e2487
commit
563780057d
1 changed files with 10 additions and 26 deletions
|
@ -1,44 +1,28 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"time"
|
"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"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newConfig(path, directory string) (*viper.Viper, error) {
|
func newConfig(path, directory string) (*viper.Viper, error) {
|
||||||
const envPrefix = "FROSTFS_IR"
|
const envPrefix = "FROSTFS_IR"
|
||||||
|
|
||||||
var (
|
var err error
|
||||||
err error
|
var dv = viper.New()
|
||||||
v = viper.New()
|
|
||||||
)
|
|
||||||
|
|
||||||
v.SetEnvPrefix(envPrefix)
|
defaultConfiguration(dv)
|
||||||
v.AutomaticEnv()
|
|
||||||
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
|
||||||
|
|
||||||
defaultConfiguration(v)
|
_, _, err = configViper.CreateViper(configViper.WithConfigFile(path),
|
||||||
|
configViper.WithConfigDir(directory), configViper.WithEnvPrefix(envPrefix),
|
||||||
if path != "" {
|
configViper.WithViper(dv))
|
||||||
v.SetConfigFile(path)
|
if err != nil {
|
||||||
if strings.HasSuffix(path, ".json") {
|
return nil, err
|
||||||
v.SetConfigType("json")
|
|
||||||
} else {
|
|
||||||
v.SetConfigType("yml")
|
|
||||||
}
|
|
||||||
if err = v.ReadInConfig(); err != nil {
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if directory != "" {
|
return dv, err
|
||||||
err = config.ReadConfigDir(v, directory)
|
|
||||||
}
|
|
||||||
|
|
||||||
return v, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultConfiguration(cfg *viper.Viper) {
|
func defaultConfiguration(cfg *viper.Viper) {
|
||||||
|
|
Loading…
Reference in a new issue