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
| Name | Type | Description |
|---|---|---|
| flags | *pflag.FlagSet | The pflag.FlagSet to bind to the configuration. This set of flags will be used to populate configuration values. |
Returns
| Type | Description |
|---|---|
error | An 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
| Name | Type | Description |
|---|---|---|
| input | string | The name of the environment variable to bind. This string specifies which environment variable to look for. |
Returns
| Type | Description |
|---|---|
error | An 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
| Type | Description |
|---|---|
error | An 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
| Name | Type | Description |
|---|---|---|
| run | func(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
| Type | Description |
|---|---|
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
| Type | Description |
|---|---|
string | The 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
| Name | Type | Description |
|---|---|---|
| in | io.Reader | The io.Reader providing the configuration data to be merged. This reader supplies the content of the configuration. |
Returns
| Type | Description |
|---|---|
error | An 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
| Type | Description |
|---|---|
(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
| Type | Description |
|---|---|
[]string | A slice of strings, where each string is the absolute path to a configuration file that was used. |