In the past I’ve been trying a lot of configuration formats like JSON, YAML, properties and much more. But in the recent past I see myself just using environment variables.
In the modern cloud age where we rely heavily on stateless services environment variables are a good fit, especially when using Docker or Kubernetes.
- godotenv loads .env files if they exist, what they usually do in my local development environments.
- envconfig “loads” existing environment variables into a struct. It supports the use of struct tags to specify alternate, default, and required environment variables.
If you have sucessfully built your configuration struct you can initialize your config as following:
Your application now loads .env files if provided or existing environment variables.
I’m happy if I could help you get some inspiration or solve your problem.
This is my first article I’ve ever published, and I’m not a native English speaker, so I’m sorry if there are some mistakes. If you found something that needs to be corrected I’d be grateful if you message me.