copier
copier copied to clipboard
Doesn't deep-copy structs provided via pointers
var user *User = &User{Name: "Jinzhu", Age: 18, Role: "Admin", Salary: 200000}
var newUser *User
err := copier.CopyWithOption(&newUser, &user, copier.Option{DeepCopy: true})
Gives copy destination is invalid
error.
https://goplay.tools/snippet/ITQqvdUwKWH
var newUser *User = &User{}
You should check the error message return
err := copier.CopyWithOption(&newUser, &user, copier.Option{DeepCopy: true})
if err != nil {
panic(err)
}
Sorry, but this isn't an error, and it is handled with an error message.
The problem exists in the second line of your example. This is messing up more with Golang than this library.
@uded thanks. Would it be better to clarify why this error is happening, e.g. if the destination is nil => "copy destination requires a non-nil pointer to a struct" not just "invalid"
@bryndin OK, valid point. Are you up to creating a PR?
yes, but it may take me some time to get to it.
Probably less than for us here :-) Will be waiting for your PR and reviewing it after we will get it ASAP...
@uded here we go ^