forked from redpanda-data/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inference.go
38 lines (34 loc) · 1 KB
/
inference.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package config
import "sort"
//------------------------------------------------------------------------------
// GetInferenceCandidates checks a generic config structure (YAML or JSON) and,
// if an explicit type value is not found, returns a list of candidate types by
// walking the root objects field names.
func GetInferenceCandidates(raw interface{}) []string {
switch t := raw.(type) {
case map[string]interface{}:
if _, exists := t["type"]; exists {
return nil
}
candidates := make([]string, 0, len(t))
for k := range t {
candidates = append(candidates, k)
}
sort.Strings(candidates)
return candidates
case map[interface{}]interface{}:
if _, exists := t["type"]; exists {
return nil
}
candidates := make([]string, 0, len(t))
for k := range t {
if kStr, isStr := k.(string); isStr {
candidates = append(candidates, kStr)
}
}
sort.Strings(candidates)
return candidates
}
return nil
}
//------------------------------------------------------------------------------