Skip to content

Commit

Permalink
Add go.mod
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Jun 12, 2019
1 parent 91bc9c9 commit 01f68ce
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Configor

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

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

Expand Down
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/jinzhu/configor

go 1.12

require (
github.com/BurntSushi/toml v0.3.1
gopkg.in/yaml.v2 v2.2.2
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
28 changes: 0 additions & 28 deletions unmarshal_json_1_10.go

This file was deleted.

18 changes: 0 additions & 18 deletions unmarshal_json_1_9.go

This file was deleted.

2 changes: 0 additions & 2 deletions unmarshal_json_1_10_test.go → unmarshal_json_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build go1.10

package configor_test

import (
Expand Down
20 changes: 20 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package configor

import (
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path"
Expand Down Expand Up @@ -156,6 +158,24 @@ func unmarshalToml(data []byte, config interface{}, errorOnUnmatchedKeys bool) e
return err
}

// unmarshalJSON unmarshals the given data into the config interface.
// If the errorOnUnmatchedKeys boolean is true, an error will be returned if there
// are keys in the data that do not match fields in the config interface.
func unmarshalJSON(data []byte, config interface{}, errorOnUnmatchedKeys bool) error {
reader := strings.NewReader(string(data))
decoder := json.NewDecoder(reader)

if errorOnUnmatchedKeys {
decoder.DisallowUnknownFields()
}

err := decoder.Decode(config)
if err != nil && err != io.EOF {
return err
}
return nil
}

func getPrefixForStruct(prefixes []string, fieldStruct *reflect.StructField) []string {
if fieldStruct.Anonymous && fieldStruct.Tag.Get("anonymous") == "true" {
return prefixes
Expand Down

0 comments on commit 01f68ce

Please sign in to comment.