Skip to main content

CollectionProxy

A proxy object for a collection of Viper instances.

Methods


BindPFlags()

@classmethod
def BindPFlags(
flags: *pflag.FlagSet
) - > error

Binds a given pflag.FlagSet to the configuration, allowing command-line flags to override configuration values. Callers use this to integrate command-line arguments into the configuration system.

Parameters

NameTypeDescription
flags*pflag.FlagSetThe pflag.FlagSet instance containing the command-line flags to bind.

Returns

TypeDescription
errorAn error if the binding fails, otherwise nil.

BindEnv()

@classmethod
def BindEnv(
input: string
) - > error

Binds a specific environment variable to a configuration key, enabling environment variables to set configuration values. Callers use this to map environment variables to their corresponding configuration settings.

Parameters

NameTypeDescription
inputstringThe name of the environment variable to bind.

Returns

TypeDescription
errorAn error if the binding fails, otherwise nil.

AutomaticEnv()

@classmethod
def AutomaticEnv()

Enables automatic binding of environment variables to configuration keys, where environment variables are expected to be prefixed with the application's name. Callers use this to automatically load configuration from environment variables without explicit binding for each variable.


ReadInConfig()

@classmethod
def ReadInConfig() - > error

Reads configuration from the configured config file path into the application. Callers use this to load the primary configuration file.

Returns

TypeDescription
errorAn error if reading the config file fails, otherwise nil.

OnConfigChange()

@classmethod
def OnConfigChange(
run: func(in fsnotify.Event)
)

Registers a callback function to be executed whenever the configuration file changes. Callers use this to react to live updates in configuration without restarting the application.

Parameters

NameTypeDescription
runfunc(in fsnotify.Event)The function to execute when a configuration change event occurs, receiving an fsnotify.Event as an argument.

WatchConfig()

@classmethod
def WatchConfig()

Starts watching for changes in the configuration file, enabling dynamic updates. Callers use this to automatically reload configuration when the file on disk is modified.


AllSettings()

@classmethod
def AllSettings() - > map[string]interface{}

Retrieves all configuration settings as a map. Callers use this to get a complete snapshot of the current configuration.

Returns

TypeDescription
map[string]interface{}A map containing all configuration keys and their corresponding values.

ConfigFileUsed()

@classmethod
def ConfigFileUsed() - > string

Returns the path to the configuration file that was loaded. Callers use this to determine which configuration file is actively being used.

Returns

TypeDescription
stringThe absolute path to the configuration file that was read.

MergeConfig()

@classmethod
def MergeConfig(
in: io.Reader
) - > error

Merges configuration from an io.Reader into the existing configuration. Callers use this to load additional configuration from a stream, such as from a string or network response.

Parameters

NameTypeDescription
inio.ReaderThe io.Reader providing the configuration data to merge.

Returns

TypeDescription
errorAn error if merging the configuration fails, otherwise nil.

MergeAllConfigs()

@classmethod
def MergeAllConfigs() - > (all Viper, err error)

Merges all available configurations from various sources (e.g., files, environment variables, flags) into a single, unified configuration. Callers use this to consolidate all configuration inputs into a final state.

Returns

TypeDescription
(all Viper, err error)A new Viper instance containing the merged configuration and an error if any merge operation fails.

ConfigFilesUsed()

@classmethod
def ConfigFilesUsed() - > []string

Returns a list of all configuration files that were loaded. Callers use this to inspect all sources of file-based configuration.

Returns

TypeDescription
[]stringA slice of strings, where each string is the path to a configuration file that was used.