configfx

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

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

func DefaultEnvironmentPrefix(configName string) string

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

func DefaultFileSearchPaths(configName string) []string

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

func NewSourceFile[T any](
	configName string,
	searchPaths ...string,
) func(*slog.Logger) Source[T]

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

func NewProvider

func NewProvider[T any](
	source Source[T],
	log *slog.Logger,
) Provider[T]

NewProvider returns a config provider to fetch the config. Internally the config source is provided by viper and parsed the moment one does call Provider[T].Config().

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

type SourceFile[T any] struct {
	Source[T]
	// contains filtered or unexported fields
}

SourceFile is a config source using files

func (*SourceFile[T]) Viper

func (s *SourceFile[T]) Viper(
	opts ...viper.Option,
) *viper.Viper

Viper implements Source[T] It returns a fresh *Viper with opts to read from using a [Provider[T]].

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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