add support for ptr to extends struct

This commit is contained in:
Lunny Xiao 2014-05-08 13:24:07 +08:00
parent a49c17bff0
commit aed19a5f81
1 changed files with 15 additions and 1 deletions

View File

@ -123,7 +123,21 @@ func (col *Column) ValueOfV(dataStruct *reflect.Value) (*reflect.Value, error) {
} else if len(col.fieldPath) == 2 {
parentField := dataStruct.FieldByName(col.fieldPath[0])
if parentField.IsValid() {
if parentField.Kind() == reflect.Struct {
fieldValue = parentField.FieldByName(col.fieldPath[1])
} else if parentField.Kind() == reflect.Ptr {
if parentField.IsNil() {
parentField.Set(reflect.New(parentField.Type().Elem()))
fieldValue = parentField.Elem().FieldByName(col.fieldPath[1])
} else {
parentField = parentField.Elem()
if parentField.IsValid() {
fieldValue = parentField.FieldByName(col.fieldPath[1])
} else {
err = fmt.Errorf("field %v is not valid", col.FieldName)
}
}
}
} else {
err = fmt.Errorf("field %v is not valid", col.FieldName)
}