mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 21:32:28 +08:00
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:
@ -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, ",", " "))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user