Skip to content

Repository files navigation

forge

Build StatuscodecovGoDocLicense

Forge is a configuration syntax and parser forked for aah framework.

Installation

require github.com/go-aah/forge v0.8.0

Example

You can see example usage in the example folder.

# example.cfg# Global directives
global = "global value";
# Pull in the "PATH" environment variable
path_env = $PATH;
# Primary section
primary {
string = "primary string value";
single = 'single quotes are allowed too';
# Semicolons are optional
integer = 500
float = 80.80
boolean = true
negative = FALSE
nothing = NULL
list = [50.5, true, false, "hello", 'world'];
# Include external files
include "./include*.cfg";
# Primary-sub section sub {
key = "primary sub key value";
}
}
# Secondary section
secondary {
another = "secondary another value";
global_reference = global;
primary_sub_key = primary.sub.key;
another_again = .another; # References secondary.another
_under = 50;
}
package main
import (
"fmt""json""github.com/go-aah/forge"
)
funcmain() {
// Parse a `SectionValue` from `example.cfg`settings, err:=forge.ParseFile("example.cfg")
iferr!=nil {
panic(err)
}
// Get a single valueifsettings.Exists("global") {
// Get `global` casted as a stringvalue, _:=settings.GetString("global")
fmt.Printf("global = \"%s\"\r\n", value)
}
// Get a nested valuevalue, err:=settings.Resolve("primary.included_setting")
fmt.Printf("primary.included_setting = \"%s\"\r\n", value.GetValue())
// You can also traverse down the sections manuallyprimary, err:=settings.GetSection("primary")
strVal, err:=primary.GetString("included_setting")
fmt.Printf("primary.included_setting = \"%s\"\r\n", strVal)
// Convert settings to a mapsettingsMap:=settings.ToMap()
fmt.Printf("global = \"%s\"\r\n", settingsMap["global"])
// Convert settings to JSONjsonBytes, err:=settings.ToJSON()
fmt.Printf("\r\n\r\n%s\r\n", string(jsonBytes))
}

Issues/Requests?

Please feel free to open a github issue for any issues you have or any feature requests.

About

Configuration file syntax and parsing for golang

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages