contextStringSlice reads a string array OR a single string OR a comma-separated string from the first matching key.
(raw map[string]json.RawMessage, keys ...string)
| 500 | // contextStringSlice reads a string array OR a single string OR a |
| 501 | // comma-separated string from the first matching key. |
| 502 | func contextStringSlice(raw map[string]json.RawMessage, keys ...string) []string { |
| 503 | for _, k := range keys { |
| 504 | v, ok := raw[k] |
| 505 | if !ok || len(v) == 0 { |
| 506 | continue |
| 507 | } |
| 508 | var arr []string |
| 509 | if err := json.Unmarshal(v, &arr); err == nil { |
| 510 | return trimNonEmpty(arr) |
| 511 | } |
| 512 | var s string |
| 513 | if err := json.Unmarshal(v, &s); err == nil { |
| 514 | if strings.Contains(s, ",") { |
| 515 | return trimNonEmpty(strings.Split(s, ",")) |
| 516 | } |
| 517 | if t := strings.TrimSpace(s); t != "" { |
| 518 | return []string{t} |
| 519 | } |
| 520 | } |
| 521 | } |
| 522 | return nil |
| 523 | } |
| 524 | |
| 525 | // trimNonEmpty trims each element and drops the empties. |
| 526 | func trimNonEmpty(in []string) []string { |