Config: Support JSON list syntax (#61288)

* Config: Separate lists either by spaces or by commas.

* Simplify space separation

* use separate function for the config strings

* Change behavior only if string contains quotes

* add test for invalid string

* Use JSON list syntax

* ignore leading spaces when process list

* Add notes about using JSON lists into the docs

* Fix typo

* Apply suggestions from code review

Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com>

Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com>
This commit is contained in:
Alexander Zobnin
2023-01-16 14:03:20 +01:00
committed by GitHub
parent 045a12047f
commit 997105c20d
5 changed files with 40 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package util
import (
"encoding/json"
"fmt"
"math"
"strings"
@ -33,6 +34,16 @@ func SplitString(str string) []string {
return []string{}
}
// JSON list syntax support
if strings.Index(strings.TrimSpace(str), "[") == 0 {
var res []string
err := json.Unmarshal([]byte(str), &res)
if err != nil {
return []string{}
}
return res
}
return strings.Fields(strings.ReplaceAll(str, ",", " "))
}