Panics on a slice of *structs
Closed this issue · 2 comments
abourget commented
Is there anything preventing from supporting copying slices of structs ?
I have a list like:
var courses []*app.Course
deepcopier.Copy(source).To(&courses)
this breaks with:
panic(0x7fce60, 0xc420113680)
/usr/local/go/src/runtime/panic.go:458 +0x243
reflect.flag.mustBe(0x197, 0x19)
/usr/local/go/src/reflect/value.go:201 +0xae
reflect.Value.NumField(0x7ff260, 0xc420113640, 0x197, 0x7ff260)
/usr/local/go/src/reflect/value.go:1152 +0x34
github.com/ulule/deepcopier.(*DeepCopier).ProcessCopy(0xc4204e11f0, 0xc420113660, 0xc4204e11d8)
/home/abourget/go/src/github.com/ulule/deepcopier/deepcopier.go:77 +0xd5
github.com/ulule/deepcopier.(*DeepCopier).To(0xc4204e11f0, 0x7f9f80, 0xc420113640, 0x7d7240, 0xc420113660)
/home/abourget/go/src/github.com/ulule/deepcopier/deepcopier.go:58 +0x5d
main.(*CoursesController).List(0xc4201125a0, 0xc420112a60, 0xc42011a120, 0xc420112a60)
Important bit is on line 77 of deepcopier.go:
fields := []string{}
val := reflect.ValueOf(dc.Tagged).Elem()
for i := 0; i < val.NumField(); i++ {
typ := val.Type().Field(i)
(the call to NumField()
...)
Thanks!
gillesfabio commented
paulschroeder-tomtom commented
What if the source struct contains a slice, can I select from that one? I.e.:
type Target struct {
Foo string `deepcopier:"field:Source.Bar[3].Value.Of.Slice"`
}