Convert string or array into a string array, otherwise return nil. If the input slice contains entries of mixed type, all string entries would be collected and returned as a slice and non-string entries as another.
(value interface{})
| 692 | // the input slice contains entries of mixed type, all string entries would |
| 693 | // be collected and returned as a slice and non-string entries as another. |
| 694 | func ValueToStringArray(value interface{}) ([]string, []interface{}) { |
| 695 | var nonStrings []interface{} |
| 696 | switch valueType := value.(type) { |
| 697 | case string: |
| 698 | return []string{valueType}, nil |
| 699 | case []string: |
| 700 | return valueType, nil |
| 701 | case []interface{}: |
| 702 | result := make([]string, 0, len(valueType)) |
| 703 | for _, item := range valueType { |
| 704 | if str, ok := item.(string); ok { |
| 705 | result = append(result, str) |
| 706 | } else { |
| 707 | nonStrings = append(nonStrings, item) |
| 708 | } |
| 709 | } |
| 710 | return result, nonStrings |
| 711 | default: |
| 712 | nonStrings = append(nonStrings, valueType) |
| 713 | return nil, nonStrings |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | // SanitizeRequestURL will return a sanitised string of the URL by: |
| 718 | // - Tagging mux path variables. |
no outgoing calls