refactor: split copier.go into smaller files
Split monolithic copier.go (1077 lines) into focused modules: - copier.go: Core framework (95 lines) - copy_value.go: Copy functions and type handling (858 lines) - reflect.go: Reflection utilities (100 lines) - converter.go: Type converter (38 lines) - options.go: Configuration (renamed from optiongs.go) Bug fixes: - Fixed string to *string copying (empty strings now work) - Fixed *time.Time to *time.Time copying - Fixed nil slice handling - Fixed copyStructToSlice pointer element handling Tests: Fixed critical data copy issues. Remaining method-mapping features require additional implementation.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package copier
|
||||
|
||||
import "reflect"
|
||||
|
||||
func (c *copier) lookupAndCopyWithConverter(dst, src reflect.Value, fieldName string) (bool, error) {
|
||||
if cnv, ok := c.opt.convertByName[fieldName]; ok {
|
||||
return convert(dst, src, cnv)
|
||||
}
|
||||
|
||||
if len(c.opt.converters) > 0 {
|
||||
pair := converterPair{
|
||||
SrcType: src.Type(),
|
||||
DstType: dst.Type(),
|
||||
}
|
||||
|
||||
if cnv, ok := c.opt.converters[pair]; ok {
|
||||
return convert(dst, src, cnv)
|
||||
}
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func convert(dst, src reflect.Value, fn convertFunc) (bool, error) {
|
||||
result, err := fn(src.Interface())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if result != nil {
|
||||
dst.Set(reflect.ValueOf(result))
|
||||
} else {
|
||||
dst.Set(reflect.Zero(dst.Type()))
|
||||
}
|
||||
|
||||
return true, nil
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user