1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

Update github.com/DisposaBoy/JsonConfigReader (#514)

This commit is contained in:
Tom Limoncelli
2019-06-30 09:05:38 -04:00
committed by GitHub
parent d5ff6d6e5c
commit ffc0a10c64
4 changed files with 37 additions and 3 deletions

View File

@ -2,3 +2,4 @@ This is the official list of JsonConfigReader authors for copyright purposes.
* DisposaBoy `https://github.com/DisposaBoy`
* Steven Osborn `https://github.com/steve918`
* Andreas Jaekle `https://github.com/ekle`

View File

@ -1,6 +1,14 @@
[![Build Status](https://travis-ci.org/DisposaBoy/JsonConfigReader.svg?branch=master)](https://travis-ci.org/DisposaBoy/JsonConfigReader)
<hr/>
JsonConfigReader is a proxy for [golang's io.Reader](http://golang.org/pkg/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.
@ -9,9 +17,15 @@ 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],
}

View File

@ -25,6 +25,24 @@ func consumeComment(s []byte, i int) int {
s[i] = ' '
}
}
if i < len(s) && s[i] == '*' {
s[i-1] = ' '
s[i] = ' '
for ; i < len(s); i += 1 {
if s[i] != '*' {
s[i] = ' '
} else {
s[i] = ' '
i++
if i < len(s) {
if s[i] == '/' {
s[i] = ' '
break
}
}
}
}
}
return i
}