action-env/cmd/frostfs-node/config/config.go
Anton Nikiforov eb7be82e87 [#125] node: Avoid panic when reading config
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
2023-04-26 13:53:51 +03:00

53 lines
1.1 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
opts configViper.Opts
defaultPath []string
path []string
}
const (
// EnvPrefix is a prefix of ENV variables related
// to storage node configuration.
EnvPrefix = "FROSTFS"
)
// Prm groups required parameters of the Config.
type Prm struct{}
// New creates a new Config instance.
//
// If file option is provided (WithConfigFile),
// configuration values are read from it.
// Otherwise, Config is a degenerate tree.
func New(_ Prm, opts ...configViper.Option) *Config {
v, o, err := configViper.CreateViper(opts...)
if err != nil {
panic(err)
}
return &Config{
v: v,
opts: *o,
}
}
// Reload reads configuration path if it was provided to New.
func (x *Config) Reload() error {
return configViper.ReloadViper(x.v, x.opts)
}