Commit 2dc9d440 authored by zauberstuhl's avatar zauberstuhl

Fix reduceStructField rendering hash instead of array

parent e203bf44
...@@ -21,7 +21,6 @@ import ( ...@@ -21,7 +21,6 @@ import (
"reflect" "reflect"
"github.com/fatih/structs" "github.com/fatih/structs"
"regexp" "regexp"
"strconv"
) )
// select only a few fields instead of the whole struct // select only a few fields instead of the whole struct
...@@ -65,12 +64,18 @@ func reduceStructField(m map[string]interface{}, fieldParam string) map[string]i ...@@ -65,12 +64,18 @@ func reduceStructField(m map[string]interface{}, fieldParam string) map[string]i
newMap[field] = reduceStructField(model, subField[3]) newMap[field] = reduceStructField(model, subField[3])
} else if kind == reflect.Slice { } else if kind == reflect.Slice {
models := m[field].([]interface{}) models := m[field].([]interface{})
newModelMap := make(map[string]interface{}, len(models)) if len(models) > 0 {
for i, m := range models { var newModelMap []interface{}
model := m.(map[string]interface{}) for _, m := range models {
newModelMap[strconv.Itoa(i)] = reduceStructField(model, subField[3]) model := m.(map[string]interface{})
newModelMap = append(newModelMap, reduceStructField(model, subField[3]))
}
newMap[field] = newModelMap
} else {
// init an empty array, otherwise the
// field will be render with null
newMap[field] = []string{}
} }
newMap[field] = newModelMap
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment