Skip to content

Commit

Permalink
verify that the modelType is a struct before interating through NumFi…
Browse files Browse the repository at this point in the history
…eld (#135)
  • Loading branch information
superpan authored and jinzhu committed Jun 2, 2018
1 parent 145964c commit 138548e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,12 +730,14 @@ func (res *Resource) configure() {

configureModel = func(value interface{}) {
modelType := utils.ModelType(value)
for i := 0; i < modelType.NumField(); i++ {
if fieldStruct := modelType.Field(i); fieldStruct.Anonymous {
if injector, ok := reflect.New(fieldStruct.Type).Interface().(resource.ConfigureResourceInterface); ok {
injector.ConfigureQorResource(res)
} else {
configureModel(reflect.New(fieldStruct.Type).Interface())
if modelType.Kind() == reflect.Struct {
for i := 0; i < modelType.NumField(); i++ {
if fieldStruct := modelType.Field(i); fieldStruct.Anonymous {
if injector, ok := reflect.New(fieldStruct.Type).Interface().(resource.ConfigureResourceInterface); ok {
injector.ConfigureQorResource(res)
} else {
configureModel(reflect.New(fieldStruct.Type).Interface())
}
}
}
}
Expand Down

0 comments on commit 138548e

Please sign in to comment.