Documentation
¶
Index ¶
- func DefaultDecoders() []mapstructure.DecodeHookFunc
- func DefaultEnvironmentPrefix(configName string) string
- func DefaultFileSearchPaths(configName string) []string
- func NewSourceFile[T any](configName string, searchPaths ...string) func(*slog.Logger) Source[T]
- type CustomDecoder
- type CustomValidator
- type Provider
- type Source
- type SourceFile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultDecoders ¶
func DefaultDecoders() []mapstructure.DecodeHookFunc
DefaultDecoders returns common decoders to be used with config parsers
func DefaultEnvironmentPrefix ¶
DefaultEnvironmentPrefix returns the default environment prefix. It searches all environment variable names for a prefix of CONFIGNAME. If such variable exists, this prefix will be used as the default environment prefix for vipers autoenv feature.
func DefaultFileSearchPaths ¶
DefaultFileSearchPaths returns default config file search paths. In order of decreasing priority the following paths are searched for a file <configName> with any supported extension by default: - <working directory>/ - $HOME/.config/ - $HOME/.<configName>/ - $HOME/.local/etc/ - $HOME/ - /opt/<configName>/ - /opt/<configName>/etc/ - /usr/local/etc/ - /etc/
func NewSourceFile ¶
NewSourceFile returns a Source constructor based on a config file. configName specifies the file to search for in default paths. A developer can optionally override searchPaths. userFlags can be used to allow adjustment of config loading by users using cobra.Command.PersistentFlags for example.
Types ¶
type CustomDecoder ¶
type CustomDecoder interface { // DecodeHook shall return the func to be used for decoding. // It will be appended to default decoders. DecodeHook() mapstructure.DecodeHookFunc }
CustomDecoder denotes types which implement a custom DecodeHook() for use with viper and mapstructure struct tags.
type CustomValidator ¶
type CustomValidator interface { // Validate shall return an error or nil when used during validation. Validate() error }
CustomValidator denotes types which implement a custom Validate() for use with config validation.
type Provider ¶
type Provider[T any] interface { // Config shall return the generic config or error Config() (*T, error) // Viper shall return the viper instance Viper() *viper.Viper }
Provider defines an interface for abstract config providers
type Source ¶
type Source[T any] interface { // Viper shall return a *viper.Viper intance for // any type implementing this interface. Viper(opts ...viper.Option) *viper.Viper }
Source defines a common interface for config sources
type SourceFile ¶
SourceFile is a config source using files