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
case TypeInt:
fallthrough
case TypeMap:
fallthrough
case TypeString:
return d.getPrimitive(k, schema)
default:
@ -104,6 +106,13 @@ func (d *FieldData) getPrimitive(
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
default:
panic(fmt.Sprintf("Unknown type: %s", schema.Type))

View File

@ -76,6 +76,21 @@ func TestFieldDataGet(t *testing.T) {
"foo",
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 {

View File

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