Skip to content

Commit

Permalink
👔 up: update the dep gookit/goutil to v0.6.15
Browse files Browse the repository at this point in the history
- resolve issues gookit/goutil#135
  • Loading branch information
inhere committed Jan 6, 2024
1 parent 7f31649 commit e25815d
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 18 deletions.
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/BurntSushi/toml v1.3.2
github.com/goccy/go-json v0.10.2
github.com/goccy/go-yaml v1.11.2
github.com/gookit/goutil v0.6.14
github.com/gookit/goutil v0.6.15
github.com/gookit/ini/v2 v2.2.2
github.com/gookit/properties v0.3.0
github.com/hashicorp/hcl v1.0.0
Expand All @@ -28,9 +28,9 @@ require (
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/zclconf/go-cty v1.13.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
)
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
github.com/gookit/goutil v0.6.14 h1:96elyOG4BvVoDaiT7vx1vHPrVyEtFfYlPPBODR0/FGQ=
github.com/gookit/goutil v0.6.14/go.mod h1:YyDBddefmjS+mU2PDPgCcjVzTDM5WgExiDv5ZA/b8I8=
github.com/gookit/goutil v0.6.15 h1:mMQ0ElojNZoyPD0eVROk5QXJPh2uKR4g06slgPDF5Jo=
github.com/gookit/goutil v0.6.15/go.mod h1:qdKdYEHQdEtyH+4fNdQNZfJHhI0jUZzHxQVAV3DaMDY=
github.com/gookit/ini/v2 v2.2.2 h1:3B8abZJrVH1vi/7TU4STuTBxdhiAq1ORSt6NJZCahaI=
github.com/gookit/ini/v2 v2.2.2/go.mod h1:wGEfnBxv+7nVXytWM44tiqczv5hLKJ+m9MaA2uJg3iM=
github.com/gookit/properties v0.3.0 h1:52NBYMOP5VXm3mKrQSdQoeEPgk2zXBGDF1R/xblsa6Y=
Expand Down Expand Up @@ -59,15 +59,15 @@ github.com/zclconf/go-cty v1.13.0 h1:It5dfKTTZHe9aeppbNOda3mN7Ag7sg6QkBNm6TkyFa0
github.com/zclconf/go-cty v1.13.0/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
76 changes: 76 additions & 0 deletions issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,79 @@ func TestIssues_162(t *testing.T) {
// dump.Println(opt)
assert.Empty(t, opt.Loggers)
}

// https://github.com/gookit/goutil/issues/135
func TestGoutil_issues_135(t *testing.T) {
// TIP: not support use JSON as default value
testYml := `
test:
credentials: >
${CREDENTIALS|{}}
apiKey: ${API_KEY|AN_APIKEY}
apiUri: ${API_URI|http://localhost:8888/v1/api}
`

type Setup struct {
Credentials string `mapstructure:"credentials"`
ApiKey string `mapstructure:"apiKey"`
ApiUri string `mapstructure:"apiUri"`
}

type Configuration struct {
Details Setup `mapstructure:"test"`
}

c := config.New("config", config.ParseEnv).WithDriver(yamlv3.Driver)

err := c.LoadStrings(config.Yaml, testYml)
assert.NoErr(t, err)

// no env values
t.Run("no env values", func(t *testing.T) {
st := Configuration{}
err = c.Decode(&st)
assert.NoErr(t, err)
dump.Println(st)
})

// set value
err = c.Set("test.credentials", `${CREDENTIALS}`)
assert.NoErr(t, err)

// set value(use JSON as default value)
err = c.Set("test.credentials", `${CREDENTIALS | {}}`)
assert.NoErr(t, err)

// with env values
t.Run("with env values", func(t *testing.T) {
testutil.MockEnvValues(map[string]string{
"CREDENTIALS": `{"username":"admin"}`,
}, func() {
st := Configuration{}
err = c.Decode(&st)
assert.NoErr(t, err)
dump.Println(st)
assert.Eq(t, `{"username":"admin"}`, st.Details.Credentials)
})
})
}

// https://github.com/gookit/config/issues/178
func TestIssues_178(t *testing.T) {
type ConferenceConfigure struct {
AuthServerEnable bool `mapstructure:"authServerEnable" default:"true"`
}

var ENVS = map[string]string{
"CONF_AUTH_SERVER_ENABLE": "authServerEnable",
}

config.WithOptions(config.ParseEnv, config.ParseTime, config.ParseDefault)
config.LoadOSEnvs(ENVS)

cfg := &ConferenceConfigure{}
err := config.Decode(cfg)
assert.NoErr(t, err)
dump.Println(cfg)

}
11 changes: 8 additions & 3 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ func (c *Config) LoadData(dataSources ...any) (err error) {
c.opts.Delimiter = defaultDelimiter
}

var loaded bool
for _, ds := range dataSources {
if smp, ok := ds.(map[string]string); ok {
loaded = true
c.LoadSMap(smp)
continue
}
Expand All @@ -213,9 +215,12 @@ func (c *Config) LoadData(dataSources ...any) (err error) {
if err != nil {
return errorx.WithStack(err)
}
loaded = true
}

c.fireHook(OnLoadData)
if loaded {
c.fireHook(OnLoadData)
}
return
}

Expand Down Expand Up @@ -325,10 +330,10 @@ func LoadFromDir(dirPath, format string) error {
//
// Example:
//
// // file: /somedir/task.json
// // file: /somedir/task.json , will use filename 'task' as key
// Config.LoadFromDir("/somedir", "json")
//
// // after load
// // after load, the data will be:
// Config.data = map[string]any{"task": file data}
func (c *Config) LoadFromDir(dirPath, format string) (err error) {
extName := "." + format
Expand Down

0 comments on commit e25815d

Please sign in to comment.