This is a Go package to parse a configuration file using JSON.
It was ogirinally developed by Stathat but we are maintaining a fork of it here due to it being a dependency to other projects we maintain.
$ go get github.com/stathat/jconfig
import (
"github.com/groundsix/jconfig"
)
Here is our example JSON file:
{
"name" : "Harry",
"age" : 22,
"pets" : ["Dog", "Cat"]
}
And to make use of this data:
package main
import (
"fmt"
"github.com/groundsix/jconfig"
)
func main() {
config := jconfig.LoadConfig("path/to/your/config.json")
name := config.GetString("name")
age := config.GetInt("age")
pets := config.GetArray("pets")
fmt.Println(pets[0]) // Dog
}
See config.go
for full API and types that can be pulled from
your config file.
$ make test
Originally written by Patrick Crosby at StatHat. (@stat_hat)
Fork currently being maintained by Ground Six. (@groundsix)