FindArrayField finds the primary array field in a response's data object. It first checks knownArrayFields in priority order, then falls back to the lexicographically smallest unknown array field for deterministic results.
(data map[string]interface{})
| 22 | // It first checks knownArrayFields in priority order, then falls back to |
| 23 | // the lexicographically smallest unknown array field for deterministic results. |
| 24 | func FindArrayField(data map[string]interface{}) string { |
| 25 | for _, name := range knownArrayFields { |
| 26 | if arr, ok := data[name]; ok { |
| 27 | if _, isArr := arr.([]interface{}); isArr { |
| 28 | return name |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | // Fallback: lexicographically first array field (deterministic) |
| 33 | var candidates []string |
| 34 | for k, v := range data { |
| 35 | if _, isArr := v.([]interface{}); isArr { |
| 36 | candidates = append(candidates, k) |
| 37 | } |
| 38 | } |
| 39 | if len(candidates) > 0 { |
| 40 | sort.Strings(candidates) |
| 41 | return candidates[0] |
| 42 | } |
| 43 | return "" |
| 44 | } |
| 45 | |
| 46 | // toGeneric normalises any Go value (structs, typed slices, …) into |
| 47 | // plain map[string]interface{} / []interface{} via a JSON round-trip so |
no outgoing calls
no test coverage detected