Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use environment variables with no need to have config file (yml,josn,etc...) #1587

Closed
1 task done
aliaqa256 opened this issue Jul 18, 2023 · 1 comment · Fixed by #1429
Closed
1 task done

Use environment variables with no need to have config file (yml,josn,etc...) #1587

aliaqa256 opened this issue Jul 18, 2023 · 1 comment · Fixed by #1429
Labels
kind/enhancement New feature or request

Comments

@aliaqa256
Copy link

Preflight Checklist

  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

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.

@aliaqa256 aliaqa256 added the kind/enhancement New feature or request label Jul 18, 2023
@github-actions
Copy link

👋 Thanks for reporting!

A maintainer will take a look at your issue shortly. 👀

In the meantime: We are working on Viper v2 and we would love to hear your thoughts about what you like or don't like about Viper, so we can improve or fix those issues.

⏰ If you have a couple minutes, please take some time and share your thoughts: https://forms.gle/R6faU74qPRPAzchZ9

📣 If you've already given us your feedback, you can still help by spreading the news,
either by sharing the above link or telling people about this on Twitter:

https://twitter.com/sagikazarmark/status/1306904078967074816

Thank you! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request
Projects
None yet
1 participant