Closed s-takehana closed 7 months ago
package main import ( "fmt" "github.com/jinzhu/copier" ) type SrcStruct1 struct { Field1 string Field2 []*SrcStruct1 Field3 []SrcStruct1 Field4 []*SrcStruct2 Field5 []SrcStruct2 } type SrcStruct2 struct { Field string } type DestStruct1 struct { Field1 string Field2 []*DestStruct1 Field3 []DestStruct1 Field4 []*DestStruct2 Field5 []DestStruct2 } type DestStruct2 struct { Field string } func main() { src := SrcStruct1{ Field1: "Field1", Field2: []*SrcStruct1{}, Field3: []SrcStruct1{}, Field4: []*SrcStruct2{}, Field5: []SrcStruct2{}, } var dest DestStruct1 copier.Copy(&dest, &src) fmt.Printf("%#v\n", dest) }
main.DestStruct1{Field1:"Field1", Field2:[]*main.DestStruct1(nil), Field3:[]main.DestStruct1(nil), Field4:[]*main.DestStruct2{}, Field5:[]main.DestStruct2{}}
Maybe fixed.
main.DestStruct1{Field1:"Field1", Field2:[]*main.DestStruct1{}, Field3:[]main.DestStruct1{}, Field4:[]*main.DestStruct2{}, Field5:[]main.DestStruct2{}}
Reproducible Example
Description
Output