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
| Name | Type | Description |
|---|---|---|
| flags | *pflag.FlagSet | The pflag.FlagSet instance containing the command-line flags to bind. |
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, enabling environment variables to set configuration values. Callers use this to map environment variables to their corresponding configuration settings.
Parameters
| Name | Type | Description |
|---|---|---|
| input | string | The name of the environment variable to bind. |
Returns
| Type | Description |
|---|---|
error | An 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
| Type | Description |
|---|---|
error | An 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
| Name | Type | Description |
|---|---|---|
| run | func(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
| Type | Description |
|---|---|
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
| Type | Description |
|---|---|
string | The 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
| Name | Type | Description |
|---|---|---|
| in | io.Reader | The io.Reader providing the configuration data to merge. |
Returns
| Type | Description |
|---|---|
error | An 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
| 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. Callers use this to inspect all sources of file-based configuration.
Returns
| Type | Description |
|---|---|
[]string | A slice of strings, where each string is the path to a configuration file that was used. |