jinzhu / copier

Copier for golang, copy value from struct to struct and more
MIT License
5.58k stars 489 forks source link

Fixed issue with nested pointer structs #157

Closed NicklasWallgren closed 1 year ago

NicklasWallgren commented 2 years ago

Fixes https://github.com/jinzhu/copier/issues/99

An alternative to using defer/recover is to utilize the FieldByIndexErr, but it's only available in 1.18+

structField, ok := source.Type().FieldByName(fieldName)
if !ok {
    return reflect.Value{}
}

field, err := source.FieldByIndexErr(structField.Index)
if err != nil {
    return reflect.Value{}
}

return field
jinzhu commented 1 year ago

Hi @NicklasWallgren can you fix those conflicts?

NicklasWallgren commented 1 year ago

@jinzhu Sure, I've rebased with master.