Configuration file syntax and parsing for golang
Clone or download
Pull request Compare This branch is 31 commits ahead of brettlangdon:master.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example added file system interface to process config files from any file system Dec 7, 2018
token added file system interface to process config files from any file system Dec 7, 2018
.travis.yml added file system interface to process config files from any file system Dec 7, 2018
CHANGELOG.md version bump to v0.8.0 and readme update Dec 13, 2018
LICENSE Add license Jun 14, 2015
Makefile add deps target to makefile Jun 21, 2015
README.md version bump to v0.8.0 and readme update Dec 13, 2018
benchmark_test.go added file system interface to process config files from any file system Dec 7, 2018
example_test.go added file system interface to process config files from any file system Dec 7, 2018
forge.go version bump to v0.8.0 and readme update Dec 13, 2018
forge_test.go added file system interface to process config files from any file system Dec 7, 2018
fs.go handling external and native fs more effectively Dec 10, 2018
go.mod added file system interface to process config files from any file system Dec 7, 2018
lint.sh add makefile and linting helper script Jun 20, 2015
list.go Add support for lists Jul 16, 2015
parser.go handling external and native fs more effectively Dec 10, 2018
primative.go make sure to handle raw int's Jun 21, 2015
primative_test.go added file system interface to process config files from any file system Dec 7, 2018
reference.go add reference struct Jun 22, 2015
scanner.go added file system interface to process config files from any file system Dec 7, 2018
section.go error msg update and code improvements Jan 4, 2017
section_test.go added file system interface to process config files from any file system Dec 7, 2018
test.cfg Merged brettlangdon#19 PR and made required changes for this PR Jul 2, 2016
test_include.cfg add include to test/benchmark config Jun 21, 2015
value.go error msg update and code improvements Jan 4, 2017

README.md

forge

Build Status codecov GoDoc License

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"
)

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.Exists("global") {
		// Get `global` casted as a string
		value, _ := settings.GetString("global")
		fmt.Printf("global = \"%s\"\r\n", value)
	}

	// 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 manually
	primary, err := settings.GetSection("primary")
	strVal, err := primary.GetString("included_setting")
	fmt.Printf("primary.included_setting = \"%s\"\r\n", strVal)

	// Convert settings to a map
	settingsMap := 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))
}

Issues/Requests?

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