• Stars
    star
    110
  • Rank 316,770 (Top 7 %)
  • Language
    Go
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Configuration file syntax and parsing for golang

forge

Build Status GoDoc

Forge is a configuration syntax and parser.

Installation

go get github.com/brettlangdon/forge

Documentation

Documentation can be viewed on godoc: https://godoc.org/github.com/brettlangdon/forge

Example

You can see example usage in the example folder.

# example.cfg

# Global directives
global = "global value";
# 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/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.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.

More Repositories

1

jsnice

Command line interface to http://jsnice.org.
JavaScript
270
star
2

git-vendor

Git command for managing git vendored dependencies
Shell
248
star
3

node-dogapi

Datadog API Node.JS Client
JavaScript
103
star
4

NodeLua

Lua Bindings For Node.JS
C++
86
star
5

flask-env

Easily set Flask settings from environment variables
Python
35
star
6

importhook

Python package for executing functions when packages are imported
JavaScript
25
star
7

jsfmt.el

emacs plugin to run jsfmt
Emacs Lisp
13
star
8

node-units

A extensible unit conversion library for Node.JS
JavaScript
12
star
9

node-kestrel

Kestrel client module for NodeJS
JavaScript
12
star
10

greenrpc

TCP & HTTP RPC Servers built on msgpack and gevent
Python
12
star
11

tommygun

HTTP Benchmarking Tool Written In Node.JS
JavaScript
10
star
12

tracking-server-examples

Code examples to follow along with http://brett.is/writing/about/third-party-tracking-pixels/
Python
8
star
13

go-dom

Web API package for use when compling Go to WASM
Go
8
star
14

qw

qw (QueueWorker) - python library for processing a redis list as a work queue
Python
7
star
15

node-wgdb

Bindings for WhiteDB for Node.JS
C++
7
star
16

sysaudit

Backport module for sys.audit and sys.addaudithook mechanism
Python
6
star
17

Programming-In-General

A language agnostic book on programming.
Python
6
star
18

tend

CLI Tool to run a command when files in a directory have changed
JavaScript
6
star
19

firestore-autocomplete

Example application using Firebase Firestore for autocomplete.
JavaScript
6
star
20

gython

Python 3 interpreter in Go
Go
5
star
21

sleuth

Simple JavaScript metrics beacon library
JavaScript
5
star
22

pypihub

pip compatible server to serve Python packages out of GitHub
Go
4
star
23

riakcached

A memcache like client for Riak
Python
3
star
24

jsonstream

Utility to interact with a stream of newline delimited JSON
Go
3
star
25

Continuous

Event based interface to setTimeout and setInterval.
JavaScript
3
star
26

ferrite

A very fast kyoto cabinet powered memcache interface http proxy caching server.
Go
3
star
27

flume-kestrel

Kestrel plugin for Flume.
Java
3
star
28

docast

Generate docs from javascript source via AST parsing
JavaScript
2
star
29

flask-defer

Flask extension to help register functions to run at the end of the current request.
Python
2
star
30

node-response-codes

Node module that extends http.ServerResponse to include status code functions.
JavaScript
2
star
31

ledger

Ledger is an event based NodeJS module used for logging events to stdout, files or MongoDB.
JavaScript
2
star
32

brett.is

My personal blog
CSS
2
star
33

cmdsrv

A simple text protocol server.
JavaScript
2
star
34

v8type

Expose V8 C++ type checking to JS
C++
2
star
35

caddydogstatsd

Datadog dogstatsd middleware plugin for Caddy.
Go
2
star
36

buildparser

Python package for parsing a build spec(s) from a config file
Python
1
star
37

flume-rabbitmq

RabbitMQ Sink Plugin for Cloudera's Flume v0.9.4
Java
1
star
38

franz

Franz is a Kafka Client for Node.JS that includes support for Zookeeper
C++
1
star
39

yaps

Yet Another Plugin Server
JavaScript
1
star
40

github-keys

Host GitHub user public keys
Go
1
star
41

virtualmod

Python package for creating and importing virtual modules.
Python
1
star
42

realm

A simple non-recursive DNS server written in Go.
Go
1
star
43

flume-hornetq

HornetQ Sink plugin for Flume.
1
star