Environment Variables with Golang !

Aman Agarwal
2 min readFeb 23, 2021
Work to learn !

Environment variables are a universal mechanism for conveying configuration information to Unix programs. Let’s look at how to set, get, and list environment variables.

As we start to build ever more complex Go-based applications, we start to face challenges when it comes to safely introducing new features, or handling credentials for the likes of databases, or brokers.

Using environment variables is an excellent way to simplify a number of different aspects such as handling credentials across various different environments, as well as simplifying the implementation of feature flags in your system.

Here the provided the Git Repository is an Optimize way of using .env file in any project. I found this method of using .env variable more suitable (personal) , fast and protective. Unlike before accessing environment with os package at every file and location,

Instead here with power of using multiple ENVIRONMENT file with hand n dependencies injection is much more convenient and readable.

We can use different-different and multiple .env fie at the time of initializing object and then smoothly access the variable respective to there accessing object.

Directly use config.go and look into main.go file for how to work with this.

For easy to use:-

Use Makefile to run a dummy test and check for correct value and flow !

make test

Resource Code

--

--

Aman Agarwal

Engineer | Explorer | Blockchain | Golang | JavaScript developer