frostfs-node/cmd/frostfs-node/config/config.go
Dmitrii Stepanov 79088baa06 [#772] node: Apply gofumpt
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-10-31 17:03:03 +03:00

59 lines
1.4 KiB
Go

package config
import (
configViper "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common/config"
"github.com/spf13/viper"
)
// Config represents a group of named values structured
// by tree type.
//
// Sub-trees are named configuration sub-sections,
// leaves are named configuration values.
// Names are of string type.
type Config struct {
v *viper.Viper
configFile string
configDir string
envPrefix string
defaultPath []string
path []string
}
const (
// EnvPrefix is a prefix of ENV variables related
// to storage node configuration.
EnvPrefix = "FROSTFS"
)
// New creates a new Config instance.
//
// If file option is provided,
// configuration values are read from it.
// Otherwise, Config is a degenerate tree.
func New(configFile, configDir, envPrefix string) *Config {
v, err := configViper.CreateViper(
configViper.WithConfigFile(configFile),
configViper.WithConfigDir(configDir),
configViper.WithEnvPrefix(envPrefix))
if err != nil {
panic(err)
}
return &Config{
v: v,
configFile: configFile,
configDir: configDir,
envPrefix: envPrefix,
}
}
// Reload reads configuration path if it was provided to New.
func (x *Config) Reload() error {
return configViper.ReloadViper(
configViper.WithViper(x.v), configViper.WithConfigFile(x.configFile),
configViper.WithConfigDir(x.configDir),
configViper.WithEnvPrefix(x.envPrefix))
}