Bump github.com/gookit/config/v2 from 2.2.3 to 2.2.4

Bumps [github.com/gookit/config/v2](https://github.com/gookit/config) from 2.2.3 to 2.2.4.
- [Release notes](https://github.com/gookit/config/releases)
- [Commits](https://github.com/gookit/config/compare/v2.2.3...v2.2.4)

---
updated-dependencies:
- dependency-name: github.com/gookit/config/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
dependabot[bot]
2023-11-03 10:26:28 +01:00
committed by Ralf Haferkamp
parent 30784affc4
commit 0df009eae0
141 changed files with 7314 additions and 4044 deletions
+14 -2
View File
@@ -76,10 +76,21 @@ func (c *Config) MapOnExists(key string, dst any) error {
//
// dbInfo := Db{}
// config.Structure("db", &dbInfo)
func (c *Config) Structure(key string, dst any) error {
func (c *Config) Structure(key string, dst any) (err error) {
var data any
// binding all data
// binding all data on key is empty.
if key == "" {
// fix: if c.data is nil, don't need to apply map structure
if len(c.data) == 0 {
// init default value by tag: default
if c.opts.ParseDefault {
err = structs.InitDefaults(dst, func(opt *structs.InitOptions) {
opt.ParseEnv = c.opts.ParseEnv
})
}
return
}
data = c.data
} else {
// binding sub-data of the config
@@ -90,6 +101,7 @@ func (c *Config) Structure(key string, dst any) error {
}
}
// map structure from data
bindConf := c.opts.makeDecoderConfig()
// set result struct ptr
bindConf.Result = dst
+15
View File
@@ -99,6 +99,21 @@ func (c *Config) Data() map[string]any {
return c.data
}
// Sub return sub config data by key
func Sub(key string) map[string]any { return dc.Sub(key) }
// Sub get sub config data by key
//
// Note: will don't apply any options, like ParseEnv
func (c *Config) Sub(key string) map[string]any {
if mp, ok := c.GetValue(key); ok {
if mmp, ok := mp.(map[string]any); ok {
return mmp
}
}
return nil
}
// Keys return all config data
func Keys() []string { return dc.Keys() }
+7 -2
View File
@@ -18,16 +18,21 @@ func ValDecodeHookFunc(parseEnv, parseTime bool) mapstructure.DecodeHookFunc {
return data, nil
}
var err error
str := data.(string)
if parseEnv {
str = envutil.ParseEnvValue(str)
// https://docs.docker.com/compose/environment-variables/env-file/
str, err = envutil.ParseOrErr(str)
if err != nil {
return nil, err
}
}
if len(str) < 2 {
return str, nil
}
// start char is number(1-9)
if str[0] > '0' && str[0] < '9' {
if str[0] > '0' && str[0] <= '9' {
// parse time string. eg: 10s
if parseTime && t.Kind() == reflect.Int64 {
dur, err := time.ParseDuration(str)