mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +00:00
refactor: make use of strings.Cut
This commit is contained in:
parent
94632fa21e
commit
f62f86a84b
1 changed files with 6 additions and 6 deletions
12
viper.go
12
viper.go
|
@ -1419,11 +1419,11 @@ func stringToStringConv(val string) any {
|
||||||
}
|
}
|
||||||
out := make(map[string]any, len(ss))
|
out := make(map[string]any, len(ss))
|
||||||
for _, pair := range ss {
|
for _, pair := range ss {
|
||||||
kv := strings.SplitN(pair, "=", 2)
|
k, vv, found := strings.Cut(pair, "=")
|
||||||
if len(kv) != 2 {
|
if !found {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
out[kv[0]] = kv[1]
|
out[k] = vv
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
@ -1439,12 +1439,12 @@ func stringToIntConv(val string) any {
|
||||||
ss := strings.Split(val, ",")
|
ss := strings.Split(val, ",")
|
||||||
out := make(map[string]any, len(ss))
|
out := make(map[string]any, len(ss))
|
||||||
for _, pair := range ss {
|
for _, pair := range ss {
|
||||||
kv := strings.SplitN(pair, "=", 2)
|
k, vv, found := strings.Cut(pair, "=")
|
||||||
if len(kv) != 2 {
|
if !found {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
out[kv[0]], err = strconv.Atoi(kv[1])
|
out[k], err = strconv.Atoi(vv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue