It's All Writing.

Writing makes you happy.

How to read config.ini which define configuration values at golang


  • go ( golang )


You have a config.ini file which define configuration values as follows and you want to load it with go.


We can easily do this using package ini. If you have not installed ini, you can install it as follow.

$ go get

The config/config.go and main.go has a structure as follows.

$ tree

├── 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.