mirror of
https://github.com/spf13/viper
synced 2024-12-22 11:37:02 +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))
|
||||
for _, pair := range ss {
|
||||
kv := strings.SplitN(pair, "=", 2)
|
||||
if len(kv) != 2 {
|
||||
k, vv, found := strings.Cut(pair, "=")
|
||||
if !found {
|
||||
return nil
|
||||
}
|
||||
out[kv[0]] = kv[1]
|
||||
out[k] = vv
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
@ -1439,12 +1439,12 @@ func stringToIntConv(val string) any {
|
|||
ss := strings.Split(val, ",")
|
||||
out := make(map[string]any, len(ss))
|
||||
for _, pair := range ss {
|
||||
kv := strings.SplitN(pair, "=", 2)
|
||||
if len(kv) != 2 {
|
||||
k, vv, found := strings.Cut(pair, "=")
|
||||
if !found {
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
out[kv[0]], err = strconv.Atoi(kv[1])
|
||||
out[k], err = strconv.Atoi(vv)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue