copier icon indicating copy to clipboard operation
copier copied to clipboard

Trying to copy a struct isn't working

Open RamVellanki opened this issue 6 years ago • 1 comments

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 }.

RamVellanki avatar Aug 21 '19 00:08 RamVellanki

Only exported fields are copied. I think because reflect can not set unreported fields.

ilius avatar Sep 06 '19 18:09 ilius