refactor: make use of `strings.Cut`

This commit is contained in:
Ville Skyttä 2023-10-04 20:52:28 +03:00 committed by Márk Sági-Kazár
parent 94632fa21e
commit f62f86a84b
1 changed files with 6 additions and 6 deletions

View File

@ -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
}