Henrique Dias 2016-07-06 10:45:43 +01:00
parent c4be1f8b54
commit a0d63bcd14
1 changed files with 16 additions and 7 deletions

View File

@ -7,6 +7,7 @@ import (
"log" "log"
"reflect" "reflect"
"sort" "sort"
"strconv"
"strings" "strings"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
@ -102,15 +103,24 @@ func rawToPretty(config interface{}, parent *Block) *Content {
cnf := map[string]interface{}{} cnf := map[string]interface{}{}
kind := reflect.TypeOf(config) kind := reflect.TypeOf(config)
if kind == reflect.TypeOf(map[interface{}]interface{}{}) { switch kind {
case reflect.TypeOf(map[interface{}]interface{}{}):
for key, value := range config.(map[interface{}]interface{}) { for key, value := range config.(map[interface{}]interface{}) {
cnf[key.(string)] = value cnf[key.(string)] = value
} }
} else if kind == reflect.TypeOf([]interface{}{}) { case reflect.TypeOf([]map[string]interface{}{}):
for key, value := range config.([]interface{}) { for index, value := range config.([]map[string]interface{}) {
cnf[string(key)] = value cnf[strconv.Itoa(index)] = value
} }
} else { case reflect.TypeOf([]map[interface{}]interface{}{}):
for index, value := range config.([]map[interface{}]interface{}) {
cnf[strconv.Itoa(index)] = value
}
case reflect.TypeOf([]interface{}{}):
for index, value := range config.([]interface{}) {
cnf[strconv.Itoa(index)] = value
}
default:
cnf = config.(map[string]interface{}) cnf = config.(map[string]interface{})
} }
@ -123,7 +133,6 @@ func rawToPretty(config interface{}, parent *Block) *Content {
if name == "title" && parent.Name == mainName { if name == "title" && parent.Name == mainName {
mainTitle = element.(string) mainTitle = element.(string)
} }
fields = append(fields, handleFlatValues(element, parent, name)) fields = append(fields, handleFlatValues(element, parent, name))
} }
} }
@ -155,7 +164,7 @@ func handleObjects(content interface{}, parent *Block, name string) *Block {
if parent.Name == mainName { if parent.Name == mainName {
c.Name = c.Title c.Name = c.Title
} else if parent.Type == arrayType { } else if parent.Type == arrayType {
c.Name = parent.Name + "[]" c.Name = parent.Name + "[" + name + "]"
} else { } else {
c.Name = parent.Name + "." + c.Title c.Name = parent.Name + "." + c.Title
} }