conf

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

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.

func LoadAll

func LoadAll(cfg any) error

LoadAll is a shorthand for using Load with all available providers.

func LoadEnv

func LoadEnv(cfg any, getenv func(string) string) error

func LoadFlags

func LoadFlags(cfg any, args []string) error

LoadFlags is a shorthand for using Load with the FlagProvider.

func LoadFlagsWithRemaining

func LoadFlagsWithRemaining(cfg any, args []string, remainingFunc func([]string)) error

LoadFlagsWithRemaining is a shorthand for using Load with the FlagProvider and a remaining function.

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

func (*PriorityProvider) StringVar

func (p *PriorityProvider) StringVar(to *string, name, fallback string, required bool)

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
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL