Skip to content

Commit

Permalink
refactor: make use of strings.Cut
Browse files Browse the repository at this point in the history
  • Loading branch information
scop authored and sagikazarmark committed Oct 6, 2023
1 parent 94632fa commit f62f86a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit f62f86a

Please sign in to comment.