|
|
11 years ago | |
|---|---|---|
| config | 11 years ago | |
| example | 11 years ago | |
| parser | 11 years ago | |
| token | 11 years ago | |
| LICENSE | 11 years ago | |
| README.md | 11 years ago | |
| example_test.go | 11 years ago | |
| forge.go | 11 years ago | |
Forge is a configuration syntax and parser.
git get github.com/brettlangdon/forge
Documentation can be viewed on godoc: https://godoc.org/github.com/brettlangdon/forge
You can see example usage in the example folder.
``cfg
global = "global value";
primary { string = "primary string value"; integer = 500; float = 80.80; boolean = true; negative = FALSE; nothing = NULL;
include "./include*.cfg";
sub { key = "primary sub key value"; } }
secondary { another = "secondary another value"; global_reference = global; primary_sub_key = primary.sub.key; another_again = .another; # References secondary.another _under = 50; }
```go
package main
import (
"fmt"
"json"
"github.com/brettlangdon/forge"
)
func main() {
// Parse a `SectionValue` from `example.cfg`
settings, err := forge.ParseFile("example.cfg")
if err != nil {
panic(err)
}
// Get a single value
if settings.Contains("global") {
// Get `global` casted as `StringValue`
value := settings.GetString("global")
fmt.Printf("global = \"%s\"\r\n", value.GetValue())
}
// Get a nested value
value, err := settings.Resolve("primary.included_setting")
fmt.Printf("primary.included_setting = \"%s\"\r\n", value.GetValue())
// You can also traverse down the sections
primary, err := settings.GetSection("primary")
value, err := primary.GetString("included_setting")
fmt.Printf("primary.included_setting = \"%s\"\r\n", value.GetValue())
// Convert settings to a map
settingsMap, err := settings.ToMap()
fmt.Printf("global = \"%s\"\r\n", settingsMap["global"])
// Convert settings to JSON
jsonBytes, err := settings.ToJSON()
fmt.Printf("\r\n\r\n%s\r\n", string(jsonBytes))
}
Please feel free to open a github issue for any issues you have or any feature requests.