Skip to content

Commit 01f68ce

Browse files
committed
Add go.mod
1 parent 91bc9c9 commit 01f68ce

7 files changed

+35
-49
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Configor
22

3-
Golang Configuration tool that support YAML, JSON, TOML, Shell Environment
3+
Golang Configuration tool that support YAML, JSON, TOML, Shell Environment (Supports Go 1.10+)
44

55
[![wercker status](https://app.wercker.com/status/9ebd3684ff8998501af5aac38a79a380/s/master "wercker status")](https://app.wercker.com/project/byKey/9ebd3684ff8998501af5aac38a79a380)
66

go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module github.com/jinzhu/configor
2+
3+
go 1.12
4+
5+
require (
6+
github.com/BurntSushi/toml v0.3.1
7+
gopkg.in/yaml.v2 v2.2.2
8+
)

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
2+
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
4+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5+
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
6+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

unmarshal_json_1_10.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

unmarshal_json_1_9.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

unmarshal_json_1_10_test.go renamed to unmarshal_json_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// +build go1.10
2-
31
package configor_test
42

53
import (

utils.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package configor
22

33
import (
4+
"encoding/json"
45
"errors"
56
"fmt"
7+
"io"
68
"io/ioutil"
79
"os"
810
"path"
@@ -156,6 +158,24 @@ func unmarshalToml(data []byte, config interface{}, errorOnUnmatchedKeys bool) e
156158
return err
157159
}
158160

161+
// unmarshalJSON unmarshals the given data into the config interface.
162+
// If the errorOnUnmatchedKeys boolean is true, an error will be returned if there
163+
// are keys in the data that do not match fields in the config interface.
164+
func unmarshalJSON(data []byte, config interface{}, errorOnUnmatchedKeys bool) error {
165+
reader := strings.NewReader(string(data))
166+
decoder := json.NewDecoder(reader)
167+
168+
if errorOnUnmatchedKeys {
169+
decoder.DisallowUnknownFields()
170+
}
171+
172+
err := decoder.Decode(config)
173+
if err != nil && err != io.EOF {
174+
return err
175+
}
176+
return nil
177+
}
178+
159179
func getPrefixForStruct(prefixes []string, fieldStruct *reflect.StructField) []string {
160180
if fieldStruct.Anonymous && fieldStruct.Tag.Get("anonymous") == "true" {
161181
return prefixes

0 commit comments

Comments
 (0)