[#44] ir: Support multiple configs

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
Denis Kirillov 2023-02-06 17:54:06 +03:00 committed by fyrchik
parent 87e69b9349
commit bed5a36235
2 changed files with 11 additions and 3 deletions

View file

@ -4,10 +4,11 @@ import (
"strings" "strings"
"time" "time"
"github.com/TrueCloudLab/frostfs-node/pkg/util/config"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
func newConfig(path string) (*viper.Viper, error) { func newConfig(path, directory string) (*viper.Viper, error) {
const envPrefix = "FROSTFS_IR" const envPrefix = "FROSTFS_IR"
var ( var (
@ -28,7 +29,13 @@ func newConfig(path string) (*viper.Viper, error) {
} else { } else {
v.SetConfigType("yml") v.SetConfigType("yml")
} }
err = v.ReadInConfig() if err = v.ReadInConfig(); err != nil {
return v, err
}
}
if directory != "" {
err = config.ReadConfigDir(v, directory)
} }
return v, err return v, err

View file

@ -35,6 +35,7 @@ func exitErr(err error) {
func main() { func main() {
configFile := flag.String("config", "", "path to config") configFile := flag.String("config", "", "path to config")
configDir := flag.String("config-dir", "", "path to config directory")
versionFlag := flag.Bool("version", false, "frostfs-ir node version") versionFlag := flag.Bool("version", false, "frostfs-ir node version")
flag.Parse() flag.Parse()
@ -44,7 +45,7 @@ func main() {
os.Exit(SuccessReturnCode) os.Exit(SuccessReturnCode)
} }
cfg, err := newConfig(*configFile) cfg, err := newConfig(*configFile, *configDir)
exitErr(err) exitErr(err)
var logPrm logger.Prm var logPrm logger.Prm