How to read config.ini which define configuration values at golang
Environment
- go ( golang )
Premise
You have a config.ini file which define configuration values as follows and you want to load it with go.
Code
We can easily do this using package ini. If you have not installed ini, you can install it as follow.
$ go get gopkg.in/ini.v1
The config/config.go and main.go has a structure as follows.
$ tree sample ├── config │ └── config.go ├── config.ini └── main.go
Now let's show to config.go and main.go.
Note that in order to load config.go in main.go, the import statement should say sample/config
. sample
is directory name which main.go belongs to.