Skip to content

Commit f62f86a

Browse files
scopsagikazarmark
authored andcommitted
refactor: make use of strings.Cut
1 parent 94632fa commit f62f86a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

viper.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,11 +1419,11 @@ func stringToStringConv(val string) any {
14191419
}
14201420
out := make(map[string]any, len(ss))
14211421
for _, pair := range ss {
1422-
kv := strings.SplitN(pair, "=", 2)
1423-
if len(kv) != 2 {
1422+
k, vv, found := strings.Cut(pair, "=")
1423+
if !found {
14241424
return nil
14251425
}
1426-
out[kv[0]] = kv[1]
1426+
out[k] = vv
14271427
}
14281428
return out
14291429
}
@@ -1439,12 +1439,12 @@ func stringToIntConv(val string) any {
14391439
ss := strings.Split(val, ",")
14401440
out := make(map[string]any, len(ss))
14411441
for _, pair := range ss {
1442-
kv := strings.SplitN(pair, "=", 2)
1443-
if len(kv) != 2 {
1442+
k, vv, found := strings.Cut(pair, "=")
1443+
if !found {
14441444
return nil
14451445
}
14461446
var err error
1447-
out[kv[0]], err = strconv.Atoi(kv[1])
1447+
out[k], err = strconv.Atoi(vv)
14481448
if err != nil {
14491449
return nil
14501450
}

0 commit comments

Comments
 (0)