Use environment variables with no need to have config file (yml,josn,etc...) #1587
Closed
1 task done
Labels
kind/enhancement
New feature or request
Preflight Checklist
Problem Description
As an avid user of the Viper package, I find it incredibly useful for managing configuration settings in my Go applications. However, I noticed that the current implementation requires explicitly declaring keys in the YAML configuration files. This poses a limitation when it comes to utilizing environment variables efficiently, especially in containerized environments or cloud-based deployment scenarios.
Proposed Solution
The suggested solution would involve extending Viper's capabilities to automatically look for environment variables corresponding to configuration keys when accessing the configuration values. If an environment variable with a matching name is found, Viper should fetch the value from the environment variable instead of the YAML file. This approach would provide more flexibility and better align with modern application deployment practices.
Alternatives Considered
Simplified Configuration: Users can manage their application's configuration more efficiently, as there will be no need to update the YAML file every time a configuration value changes.
Containerization Support: With this enhancement, developers can easily configure their applications using environment variables, which is a common practice in containerized environments.
Enhanced Security: Storing sensitive information in environment variables instead of configuration files reduces the risk of accidental exposure.
Easier Cloud Integration: Cloud platforms often provide the ability to manage configuration via environment variables, making this feature essential for smooth integration with various cloud services.
Additional Information
I understand that some users may prefer the current approach, where configuration keys are explicitly defined in YAML files. To maintain backward compatibility and ensure the flexibility of this feature, the solution could be implemented as an optional flag or a configuration option that users can enable or disable according to their specific requirements.
I noticed that other configuration libraries for Go, such as envconfig and godotenv, have implemented similar functionality. Studying their approaches might provide some insights and best practices for integrating environment variables seamlessly.
The text was updated successfully, but these errors were encountered: