logical/framework: Adding TypeMap
This commit is contained in:
parent
19283eb5f7
commit
cb66c93a34
|
@ -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))
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -10,6 +10,7 @@ const (
|
|||
TypeString FieldType = iota
|
||||
TypeInt
|
||||
TypeBool
|
||||
TypeMap
|
||||
)
|
||||
|
||||
// FieldType has more methods defined on it in backend.go. They aren't
|
||||
|
|
Loading…
Reference in New Issue