We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
type B struct { id string } type A struct { InsB *B } func main() { insB1 := &B{"test"} insA1 := &A{insB1} insA2 := &A{} deepcopier.Copy(insA1).To(insA2) fmt.Printf("%+v", insA1) fmt.Printf("%+v", insA2) }
I want insA2.InsB is insB2
The text was updated successfully, but these errors were encountered:
Did you find any generic deep-copier in golang?
Sorry, something went wrong.
It seems like https://github.com/mohae/deepcopy has the behaviour you want:
package main import ( "fmt" "github.com/mohae/deepcopy" ) type B struct { Id string } type A struct { InsB *B } func main() { insB1 := &B{"test"} insA1 := &A{insB1} insA2 := deepcopy.Copy(insA1) fmt.Printf("insA1: %+v | %s\n", insA1, insA1) fmt.Printf("insA2: %+v | %s\n", insA2, insA2) }
Console output:
insA1: &{InsB:0xc42000e1f0} | &{%!s(*main.B=&{test})} insA2: &{InsB:0xc42000e210} | &{%!s(*main.B=&{test})}
Note that I changed the changed the id field to be exported, as you can only set exported fields via reflection.
id
No branches or pull requests
I want insA2.InsB is insB2
The text was updated successfully, but these errors were encountered: