[#125] node: Move viper creation to internal/common/config

Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
Anton Nikiforov 2023-04-20 12:44:39 +03:00
parent b2123bfd1a
commit d390f093e0
9 changed files with 101 additions and 76 deletions

View file

@ -0,0 +1,38 @@
package config
type Opts struct {
Path string
ConfigDir string
EnvPrefix string
}
func DefaultOpts() *Opts {
return new(Opts)
}
// Option allows to set an optional parameter of the Config.
type Option func(*Opts)
// WithConfigFile returns an option to set the system path
// to the configuration file.
func WithConfigFile(path string) Option {
return func(o *Opts) {
o.Path = path
}
}
// WithConfigDir returns an option to set the system path
// to the directory with configuration files.
func WithConfigDir(path string) Option {
return func(o *Opts) {
o.ConfigDir = path
}
}
// WithEnvPrefix returns an option to defines
// a prefix that ENVIRONMENT variables will use.
func WithEnvPrefix(envPrefix string) Option {
return func(o *Opts) {
o.EnvPrefix = envPrefix
}
}