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. This is useful for integrating command-line arguments directly into the configuration system.

Parameters

NameTypeDescription
flags*pflag.FlagSetThe pflag.FlagSet to bind to the configuration. This set of flags will be used to populate configuration values.

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, allowing environment variables to set configuration values. This is useful for externalizing configuration without modifying configuration files.

Parameters

NameTypeDescription
inputstringThe name of the environment variable to bind. This string specifies which environment variable to look for.

Returns

TypeDescription
errorAn error if the binding fails, otherwise nil.

AutomaticEnv()

@classmethod
def AutomaticEnv()

Enables automatic binding of all environment variables to configuration keys. This is useful for automatically mapping environment variables to configuration settings without explicit binding calls.


ReadInConfig()

@classmethod
def ReadInConfig() - > error

Reads the configuration from the configured paths and file names into the application. This is essential for loading initial configuration settings from disk.

Returns

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

OnConfigChange()

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

Registers a callback function to be executed when the configuration file changes. This allows the application to react dynamically to configuration updates without restarting.

Parameters

NameTypeDescription
runfunc(in fsnotify.Event)The function to execute when a configuration change event occurs. This function receives an fsnotify.Event detailing the change.

WatchConfig()

@classmethod
def WatchConfig()

Starts watching for changes in the configuration file. This enables dynamic reloading of configuration without manual intervention.


AllSettings()

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

Retrieves all configuration settings as a map. This is useful for inspecting the entire configuration state or for serialization purposes.

Returns

TypeDescription
map[string]interface{}A map containing all current configuration settings, where keys are configuration paths and values are their corresponding settings.

ConfigFileUsed()

@classmethod
def ConfigFileUsed() - > string

Returns the path to the configuration file that was loaded. This is useful for debugging or logging which configuration file is actively being used.

Returns

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

MergeConfig()

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

Merges configuration from an io.Reader into the current configuration. This allows for loading configuration from arbitrary sources, such as network streams or embedded resources.

Parameters

NameTypeDescription
inio.ReaderThe io.Reader providing the configuration data to be merged. This reader supplies the content of the configuration.

Returns

TypeDescription
errorAn error if the merge operation 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. This is useful for consolidating configuration from multiple locations.

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. This is useful for understanding the complete set of configuration sources contributing to the current application state.

Returns

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