Documentation ¶
Index ¶
- func Load(cfg any, opts ...LoadOption) error
- func LoadAll(cfg any) error
- func LoadEnv(cfg any, getenv func(string) string) error
- func LoadFlags(cfg any, args []string) error
- func LoadFlagsWithRemaining(cfg any, args []string, remainingFunc func([]string)) error
- type EnvProvider
- func (p *EnvProvider) AddDotEnv() error
- func (p *EnvProvider) BoolVar(to *bool, name string, fallback bool, required bool)
- func (p *EnvProvider) IntVar(to *int, name string, fallback int, required bool)
- func (p *EnvProvider) Load() error
- func (p *EnvProvider) Missing() []string
- func (p *EnvProvider) StringVar(to *string, name, fallback string, required bool)
- func (p *EnvProvider) WithDotEnv(r io.ReadCloser) *EnvProvider
- type FlagProvider
- func (p *FlagProvider) BoolVar(to *bool, name string, fallback bool, required bool)
- func (p *FlagProvider) IntVar(to *int, name string, fallback int, required bool)
- func (p *FlagProvider) Load() error
- func (p *FlagProvider) Missing() []string
- func (p *FlagProvider) StringVar(to *string, name, fallback string, required bool)
- func (p *FlagProvider) WithRemainingFunc(f func(remaining []string)) *FlagProvider
- type LoadOption
- type PriorityProvider
- func (p *PriorityProvider) BoolVar(to *bool, name string, fallback bool, required bool)
- func (p *PriorityProvider) IntVar(to *int, name string, fallback int, required bool)
- func (p *PriorityProvider) Load() error
- func (p *PriorityProvider) Missing() []string
- func (p *PriorityProvider) StringVar(to *string, name, fallback string, required bool)
- type Provider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Load ¶
func Load(cfg any, opts ...LoadOption) error
Load loads configuration values into the given struct cfg. cfg must be a pointer to a struct. If no providers are given via the LoadOptions, the default provider is the environment, using os.Getenv.
Types ¶
type EnvProvider ¶
type EnvProvider struct {
// contains filtered or unexported fields
}
func NewEnvProvider ¶
func NewEnvProvider(getenv func(string) string) *EnvProvider
func (*EnvProvider) AddDotEnv ¶
func (p *EnvProvider) AddDotEnv() error
func (*EnvProvider) BoolVar ¶
func (p *EnvProvider) BoolVar(to *bool, name string, fallback bool, required bool)
func (*EnvProvider) IntVar ¶
func (p *EnvProvider) IntVar(to *int, name string, fallback int, required bool)
func (*EnvProvider) Load ¶
func (p *EnvProvider) Load() error
Load reads the configuration from the environment variables.
func (*EnvProvider) Missing ¶
func (p *EnvProvider) Missing() []string
func (*EnvProvider) StringVar ¶
func (p *EnvProvider) StringVar(to *string, name, fallback string, required bool)
func (*EnvProvider) WithDotEnv ¶
func (p *EnvProvider) WithDotEnv(r io.ReadCloser) *EnvProvider
type FlagProvider ¶
type FlagProvider struct {
// contains filtered or unexported fields
}
func NewFlagProvider ¶
func NewFlagProvider(args []string) *FlagProvider
NewFlagProvider creates a new FlagProvider that reads flags into `conf` tags. The remainingFunc is called with the remaining arguments, useful for subcommands. Can be nil.
func (*FlagProvider) BoolVar ¶
func (p *FlagProvider) BoolVar(to *bool, name string, fallback bool, required bool)
func (*FlagProvider) IntVar ¶
func (p *FlagProvider) IntVar(to *int, name string, fallback int, required bool)
func (*FlagProvider) Load ¶
func (p *FlagProvider) Load() error
func (*FlagProvider) Missing ¶
func (p *FlagProvider) Missing() []string
func (*FlagProvider) StringVar ¶
func (p *FlagProvider) StringVar(to *string, name, fallback string, required bool)
func (*FlagProvider) WithRemainingFunc ¶
func (p *FlagProvider) WithRemainingFunc(f func(remaining []string)) *FlagProvider
type LoadOption ¶
type LoadOption func(*loadConfig)
func WithProviders ¶
func WithProviders(providers ...Provider) LoadOption
WithProviders returns a LoadOption that sets multiple "providers" (sources of configuration values) to be used in order of priority. Later providers will override values from earlier providers. Only non-empty values will override.
type PriorityProvider ¶
type PriorityProvider struct {
// contains filtered or unexported fields
}
func NewPriorityProvider ¶
func NewPriorityProvider(providers ...Provider) *PriorityProvider
func (*PriorityProvider) BoolVar ¶
func (p *PriorityProvider) BoolVar(to *bool, name string, fallback bool, required bool)
func (*PriorityProvider) IntVar ¶
func (p *PriorityProvider) IntVar(to *int, name string, fallback int, required bool)
func (*PriorityProvider) Load ¶
func (p *PriorityProvider) Load() error
func (*PriorityProvider) Missing ¶
func (p *PriorityProvider) Missing() []string
type Provider ¶
type Provider interface { // StringVar registers a pointer to a string that will be set to the value of // the configuration parameter with the given name. If the parameter is // not set, the fallback value will be used. If the parameter is // required and not set, it will be considered missing. StringVar(to *string, name, fallback string, required bool) IntVar(to *int, name string, fallback int, required bool) BoolVar(to *bool, name string, fallback bool, required bool) // Load loads the actual values into the pointers. It should be called // after all calls to Var. Load() error // Missing returns a list of missing required configuration parameters. // It must only be called after Load, as otherwise it will always be // empty. Missing() []string }