MCPcopy
hub / github.com/larksuite/cli / FindArrayField

Function FindArrayField

internal/output/format.go:24–44  ·  view source on GitHub ↗

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{})

Source from the content-addressed store, hash-verified

22// It first checks knownArrayFields in priority order, then falls back to
23// the lexicographically smallest unknown array field for deterministic results.
24func 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

Callers 3

mergePagedResultsFunction · 0.92
StreamPagesMethod · 0.92
ExtractItemsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected