2021-05-21 11:50:40 +00:00
|
|
|
package config
|
|
|
|
|
2023-04-20 09:44:39 +00:00
|
|
|
type Opts struct {
|
|
|
|
Path string
|
|
|
|
ConfigDir string
|
|
|
|
EnvPrefix string
|
2021-05-21 11:50:40 +00:00
|
|
|
}
|
|
|
|
|
2023-04-20 09:44:39 +00:00
|
|
|
func DefaultOpts() *Opts {
|
|
|
|
return new(Opts)
|
2021-05-21 11:50:40 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Option allows to set an optional parameter of the Config.
|
2023-04-20 09:44:39 +00:00
|
|
|
type Option func(*Opts)
|
2021-05-21 11:50:40 +00:00
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// WithConfigFile returns an option to set the system path
|
2021-05-21 11:50:40 +00:00
|
|
|
// to the configuration file.
|
|
|
|
func WithConfigFile(path string) Option {
|
2023-04-20 09:44:39 +00:00
|
|
|
return func(o *Opts) {
|
|
|
|
o.Path = path
|
2021-05-21 11:50:40 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-06 13:53:16 +00:00
|
|
|
|
|
|
|
// WithConfigDir returns an option to set the system path
|
|
|
|
// to the directory with configuration files.
|
|
|
|
func WithConfigDir(path string) Option {
|
2023-04-20 09:44:39 +00:00
|
|
|
return func(o *Opts) {
|
|
|
|
o.ConfigDir = path
|
2023-02-06 13:53:16 +00:00
|
|
|
}
|
|
|
|
}
|
2023-04-20 09:17:03 +00:00
|
|
|
|
|
|
|
// WithEnvPrefix returns an option to defines
|
|
|
|
// a prefix that ENVIRONMENT variables will use.
|
|
|
|
func WithEnvPrefix(envPrefix string) Option {
|
2023-04-20 09:44:39 +00:00
|
|
|
return func(o *Opts) {
|
|
|
|
o.EnvPrefix = envPrefix
|
2023-04-20 09:17:03 +00:00
|
|
|
}
|
|
|
|
}
|