in terraformutils/walk.go [37:83]
func walkAndGet(path string, data interface{}) (bool, []interface{}) {
val := reflect.ValueOf(data)
if data == nil {
if path == "" {
return true, []interface{}{}
}
return false, []interface{}{}
}
if isArray(val.Interface()) {
var arrayValues []interface{}
for i := 0; i < val.Len(); i++ {
foundField, fieldValue := walkAndGet(path, val.Index(i).Interface())
if foundField {
arrayValues = append(arrayValues, fieldValue...)
}
}
return len(arrayValues) > 0, arrayValues
}
if val.Kind() == reflect.Map {
for _, e := range val.MapKeys() {
v := val.MapIndex(e)
pathFirstElement := strings.SplitN(path, ".", 2)
if e.String() == pathFirstElement[0] {
var pathReminder = ""
if len(pathFirstElement) > 1 {
pathReminder = pathFirstElement[1]
}
hasField, value := walkAndGet(pathReminder, v.Interface())
if !hasField {
hasField, value = walkAndGet(path, v.Interface())
}
return hasField, value
} else if e.String() == path {
return walkAndGet("", v.Interface())
}
}
}
if val.Kind() == reflect.String && path == "" {
return true, []interface{}{val.Interface()}
}
return false, []interface{}{}
}