This is a Go package to parse a configuration file using JSON.
It's really simple (under 100 lines of code) and does nothing fancy. We wouldn't have bothered releasing it except that a few other projects we will be releasing depend on it.
Use go install:
go install github.com/stathat/jconfig
If you are building your Go code with go install, you can skip the previous step and just import jconfig as follows:
import (
"github.com/stathat/jconfig"
)
Write your config file as a JSON object. For example:
{
"host_and_port": ":9556",
"environment": "production",
"priority_level": 20,
"alert_recipients": ["patrick", "gus"]
}
Load the config file:
config := jconfig.LoadConfig("/etc/super.conf")
Get some values out of it:
if config.GetString("environment") == "production" {
// ...
}
sender := NewSender(config.GetInt("priority_level"))
sender.Recipients = config.GetArray("alert_recipients")
That's all it does.
We'd love to hear from you if you are using this in your projects! Please drop us a line.
Patrick Crosby
For more information on StatHat, visit the home page.