copier
copier copied to clipboard
Trying to copy a struct isn't working
I was trying to use the copier to copy a struct but isn't working for me. Following is the code:
https://goplay.space/#ARoaaKRtM2K
type Cat struct {
age int
name string
}
func main() {
firstCat := Cat{7, "Wilson"}
secondCat := Cat{}
copier.Copy(&secondCat, &firstCat)
fmt.Println(firstCat)
fmt.Println(secondCat)
}
I expect the output to print {7, "Wilson"} two times but it prints {7, "Wilson"} {0 }.
Only exported fields are copied.
I think because reflect can not set unreported fields.