Skip to content

Commit

Permalink
format codes, and upgrade ini to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jun 8, 2019
1 parent a119c22 commit 92988dd
Show file tree
Hide file tree
Showing 28 changed files with 91 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ before_install:
- go get golang.org/x/tools/cmd/cover

script:
# - go test -v -cover
# - go test -v -cover
- $HOME/gopath/bin/goveralls -service=travis-ci
1 change: 1 addition & 0 deletions _examples/ini.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main

import (
"fmt"

"github.com/gookit/config/v2"
"github.com/gookit/config/v2/ini"
)
Expand Down
1 change: 1 addition & 0 deletions _examples/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"

"github.com/gookit/config/v2"
"github.com/gookit/config/v2/json"
)
Expand Down
1 change: 1 addition & 0 deletions _examples/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"

"github.com/gookit/config/v2"
"github.com/gookit/config/v2/toml"
)
Expand Down
1 change: 1 addition & 0 deletions _examples/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"

"github.com/gookit/config/v2"
"github.com/gookit/config/v2/yaml"
)
Expand Down
3 changes: 2 additions & 1 deletion config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package config
import (
"bytes"
"fmt"
"testing"

"github.com/gookit/config/v2/dotnev"
"github.com/stretchr/testify/assert"
"testing"
)

var jsonStr = `{
Expand Down
3 changes: 2 additions & 1 deletion dotnev/dotenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package dotnev

import (
"bufio"
"github.com/gookit/ini/parser"
"os"
"path/filepath"
"strings"

"github.com/gookit/ini/v2/parser"
)

// DefaultName default file name
Expand Down
3 changes: 2 additions & 1 deletion dotnev/dotenv_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package dotnev

import (
"github.com/stretchr/testify/assert"
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestLoad(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ go 1.12

require (
github.com/BurntSushi/toml v0.3.1
github.com/gookit/ini v1.1.1
github.com/gookit/ini/v2 v2.0.2
github.com/hashicorp/hcl v1.0.0
github.com/imdario/mergo v0.3.7
github.com/json-iterator/go v1.1.6
github.com/kr/pretty v0.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.3.0
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v2 v2.2.2
Expand Down
1 change: 1 addition & 0 deletions hcl/hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package hcl

import (
"errors"

"github.com/gookit/config/v2"
"github.com/hashicorp/hcl"
)
Expand Down
3 changes: 2 additions & 1 deletion hcl/hcl_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package hcl

import (
"testing"

"github.com/gookit/config/v2"
"github.com/stretchr/testify/assert"
"testing"
)

func TestDriver(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion ini/ini.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package ini

import (
"github.com/gookit/config/v2"
"github.com/gookit/ini/parser"
"github.com/gookit/ini/v2/parser"
)

// Decoder the ini content decoder
Expand Down
3 changes: 2 additions & 1 deletion ini/ini_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package ini

import (
"fmt"
"testing"

"github.com/gookit/config/v2"
"github.com/stretchr/testify/assert"
"testing"
)

func Example() {
Expand Down
3 changes: 2 additions & 1 deletion json/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package json

import (
"fmt"
"testing"

"github.com/gookit/config/v2"
"github.com/stretchr/testify/assert"
"testing"
)

func Example() {
Expand Down
3 changes: 2 additions & 1 deletion json_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package config

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestStripJSONComments(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"errors"
"flag"
"fmt"
"github.com/imdario/mergo"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"
"time"

"github.com/imdario/mergo"
)

// LoadFiles load one or multi files
Expand Down Expand Up @@ -95,7 +96,7 @@ func LoadFlags(keys []string) error { return dc.LoadFlags(keys) }

// LoadFlags parse command line arguments, based on provide keys.
// Usage:
// // debug flag is bool type
// // debug flag is bool type
// c.LoadFlags([]string{"env", "debug:bool"})
func (c *Config) LoadFlags(keys []string) (err error) {
hash := map[string]interface{}{}
Expand Down
5 changes: 3 additions & 2 deletions load_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package config

import (
"github.com/gookit/config/v2/dotnev"
"github.com/stretchr/testify/assert"
"os"
"testing"

"github.com/gookit/config/v2/dotnev"
"github.com/stretchr/testify/assert"
)

func TestDefaultLoad(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion read.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (c *Config) Float(key string, defVal ...float64) (value float64) {
str, ok := c.getString(key)
if !ok {
if len(defVal) > 0 {
value = defVal[0]
value = defVal[0]
}
return
}
Expand Down
3 changes: 2 additions & 1 deletion read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package config

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestConfig_GetValue(t *testing.T) {
Expand Down
46 changes: 23 additions & 23 deletions testdata/json_base.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"name": "app",
"debug": false,
"baseKey": "value",
"age": 123,
"envKey": "${SHELL}",
"envKey1": "${NotExist|defValue}",
"map1": {
"key": "val",
"key1": "val1",
"key2": "val2"
},
"arr1": [
"val",
"val1",
"val2"
],
"lang": {
"dir": "res/lang",
"defLang": "en",
"allowed": {
"en": "val",
"zh-CN": "val2"
}
"name": "app",
"debug": false,
"baseKey": "value",
"age": 123,
"envKey": "${SHELL}",
"envKey1": "${NotExist|defValue}",
"map1": {
"key": "val",
"key1": "val1",
"key2": "val2"
},
"arr1": [
"val",
"val1",
"val2"
],
"lang": {
"dir": "res/lang",
"defLang": "en",
"allowed": {
"en": "val",
"zh-CN": "val2"
}
}
}
24 changes: 12 additions & 12 deletions testdata/json_other.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "app2",
"debug": false,
"age": 12,
"baseKey": "value2",
"map1": {
"key": "val2",
"key2": "val20"
},
"arr1": [
"val1",
"val21"
]
"name": "app2",
"debug": false,
"age": 12,
"baseKey": "value2",
"map1": {
"key": "val2",
"key2": "val20"
},
"arr1": [
"val1",
"val21"
]
}
22 changes: 11 additions & 11 deletions testdata/yml_base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ envKey: ${SHELL}
envKey1: ${NotExist|defValue}

map1:
key: val
key1: val1
key2: val2
key: val
key1: val1
key2: val2

arr1:
- val
- val1
- val2
- val
- val1
- val2

lang:
dir: res/lang
defLang: en
allowed:
en: val
zh-CN: val2
dir: res/lang
defLang: en
allowed:
en: val
zh-CN: val2
8 changes: 4 additions & 4 deletions testdata/yml_other.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ age: 12
baseKey: value2

map1:
key: val2
key2: val20
key: val2
key2: val20

arr1:
- val1
- val21
- val1
- val21
1 change: 1 addition & 0 deletions toml/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package toml
// see https://godoc.org/github.com/BurntSushi/toml
import (
"bytes"

"github.com/BurntSushi/toml"
"github.com/gookit/config/v2"
)
Expand Down
3 changes: 2 additions & 1 deletion toml/toml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package toml

import (
"fmt"
"testing"

"github.com/gookit/config/v2"
"github.com/stretchr/testify/assert"
"testing"
)

var tomlStr = `
Expand Down
3 changes: 2 additions & 1 deletion write.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package config
import (
"errors"
"fmt"
"github.com/imdario/mergo"
"strconv"
"strings"

"github.com/imdario/mergo"
)

// Set val by key
Expand Down
3 changes: 2 additions & 1 deletion write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package config

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestSet(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion yaml/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package yaml
import (
"bytes"
"fmt"
"testing"

"github.com/gookit/config/v2"
"github.com/stretchr/testify/assert"
"testing"
)

var yamlStr = `
Expand Down

0 comments on commit 92988dd

Please sign in to comment.