A powerful configuration package for go using Loose JSON as the format. (godoc)
Data format
The data format is the Loose JSON, which is full compatible with JSON format but more easier for writing by hand. Visit Loose JSON project for more details.
Lines starting with //
or ;
(excluding the leading spaces) are considered as comments and thus ignored.
Dot-seperated hierarchical key
For configure:
{
// http settings
http: {
addr: "www.example.com"
ports: [80, 8080]
}
}
You can fetch values by different ways:
code | value | type |
---|---|---|
String("http.addr") |
"www.example.com" |
string |
IntList("http.ports") |
[80, 8080] |
[]int |
Int("http.ports[1]") |
8080 |
int |
Object("http") |
map[addr:www...] |
map[string]interface{} |
Include function
main.conf
{
http: {
#include#: "addr.conf"
}
}
addr.conf
{
addr: "www.example.com"
ports: [80, 8080]
}
we got:
{
http: {
addr: "www.example.com"
ports: [80, 8080]
}
}
Multi-path searching
We calling Load
function, it searches the following path in order:
- For absolute path, it is directly used,
- Current directory,
- Directory of the executable, and
- User's home directory
BSD license.