decoding maps works

This commit is contained in:
Mitchell Hashimoto 2014-08-11 16:38:36 -07:00
parent f340e2e557
commit 61e6b8179b
2 changed files with 6 additions and 16 deletions

View File

@ -187,22 +187,13 @@ func (d *decoder) decodeMap(name string, o *hcl.Object, result reflect.Value) er
} }
// Go through each element and decode it. // Go through each element and decode it.
/* m := o.Value.(map[string]*hcl.Object)
for _, n := range obj.Elem { for _, o := range m {
objValue := n.Value
// If we have an object node, expand to a list of objects
if _, ok := objValue.(ast.ObjectNode); ok {
objValue = ast.ListNode{
Elem: []ast.Node{objValue},
}
}
// Make the field name // Make the field name
fieldName := fmt.Sprintf("%s.%s", name, n.Key()) fieldName := fmt.Sprintf("%s.%s", name, o.Key)
// Get the key/value as reflection values // Get the key/value as reflection values
key := reflect.ValueOf(n.Key()) key := reflect.ValueOf(o.Key)
val := reflect.Indirect(reflect.New(resultElemType)) val := reflect.Indirect(reflect.New(resultElemType))
// If we have a pre-existing value in the map, use that // If we have a pre-existing value in the map, use that
@ -212,14 +203,13 @@ func (d *decoder) decodeMap(name string, o *hcl.Object, result reflect.Value) er
} }
// Decode! // Decode!
if err := d.decode(fieldName, objValue, val); err != nil { if err := d.decode(fieldName, o, val); err != nil {
return err return err
} }
// Set the value on the map // Set the value on the map
resultMap.SetMapIndex(key, val) resultMap.SetMapIndex(key, val)
} }
*/
// Set the final map if we can // Set the final map if we can
set.Set(resultMap) set.Set(resultMap)

View File

@ -7,7 +7,7 @@ import (
"testing" "testing"
) )
func TestDecode(t *testing.T) { func TestDecode_interface(t *testing.T) {
cases := []struct { cases := []struct {
File string File string
Err bool Err bool