helper/schema: use reflection to build []interface{}

This commit is contained in:
Mitchell Hashimoto 2014-08-18 14:24:04 -07:00
parent 17d29f7949
commit ce42845acd
1 changed files with 7 additions and 2 deletions

View File

@ -224,10 +224,15 @@ func (m schemaMap) diffList(
} }
} }
vs, ok := v.([]interface{}) // We have to use reflection to build the []interface{} list
if !ok { rawV := reflect.ValueOf(v)
if rawV.Kind() != reflect.Slice {
return fmt.Errorf("%s: must be a list", k) return fmt.Errorf("%s: must be a list", k)
} }
vs := make([]interface{}, rawV.Len())
for i, _ := range vs {
vs[i] = rawV.Index(i).Interface()
}
// If this field is required, then it must also be non-empty // If this field is required, then it must also be non-empty
if len(vs) == 0 && schema.Required { if len(vs) == 0 && schema.Required {