JsonConfigReader

package module
v0.0.0-...-99cf318 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2020 License: MIT Imports: 2 Imported by: 83

README

Build Status


JsonConfigReader is a proxy for golang's io.Reader that strips line comments and trailing commas, allowing you to use json as a reasonable config format.

Comments start with // and continue to the end of the line. Multiline comments are also supported with /* and */.

If a trailing comma is in front of ] or } it will be stripped as well.

Given settings.json

{
	"key": "value", // k:v

	// a list of numbers
	"list": [1, 2, 3],

	/* 
	a list of numbers
	which are important
	*/
	"numbers": [1, 2, 3],
}

You can read it in as a normal json file:

package main

import (
	"encoding/json"
	"fmt"
	"github.com/DisposaBoy/JsonConfigReader"
	"os"
)

func main() {
	var v interface{}
	f, _ := os.Open("settings.json")
	// wrap our reader before passing it to the json decoder
	r := JsonConfigReader.New(f)
	json.NewDecoder(r).Decode(&v)
	fmt.Println(v)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(r io.Reader) io.Reader

New returns an io.Reader acting as proxy to r

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL