logical/framework: Adding TypeMap

This commit is contained in:
Armon Dadgar 2015-03-31 16:06:15 -07:00
parent 19283eb5f7
commit cb66c93a34
3 changed files with 25 additions and 0 deletions

View File

@ -68,6 +68,8 @@ func (d *FieldData) GetOkErr(k string) (interface{}, bool, error) {
fallthrough fallthrough
case TypeInt: case TypeInt:
fallthrough fallthrough
case TypeMap:
fallthrough
case TypeString: case TypeString:
return d.getPrimitive(k, schema) return d.getPrimitive(k, schema)
default: default:
@ -104,6 +106,13 @@ func (d *FieldData) getPrimitive(
return nil, true, err return nil, true, err
} }
return result, true, nil
case TypeMap:
var result map[string]interface{}
if err := mapstructure.WeakDecode(raw, &result); err != nil {
return nil, true, err
}
return result, true, nil return result, true, nil
default: default:
panic(fmt.Sprintf("Unknown type: %s", schema.Type)) panic(fmt.Sprintf("Unknown type: %s", schema.Type))

View File

@ -76,6 +76,21 @@ func TestFieldDataGet(t *testing.T) {
"foo", "foo",
false, false,
}, },
"map type, map value": {
map[string]*FieldSchema{
"foo": &FieldSchema{Type: TypeMap},
},
map[string]interface{}{
"foo": map[string]interface{}{
"child": true,
},
},
"foo",
map[string]interface{}{
"child": true,
},
},
} }
for name, tc := range cases { for name, tc := range cases {

View File

@ -10,6 +10,7 @@ const (
TypeString FieldType = iota TypeString FieldType = iota
TypeInt TypeInt
TypeBool TypeBool
TypeMap
) )
// FieldType has more methods defined on it in backend.go. They aren't // FieldType has more methods defined on it in backend.go. They aren't