I'm aware that since Go 1.8 it's possible to assign one struct to another struct type like this:
func example() {
type T1 struct {
X intjson:"foo"
}
type T2 struct {
X intjson:"bar"
}
var v1 T1
var v2 T2
v1 = T1(v2) // now legal
}
However, if the struct internally has one of its fields as another struct, it doesn't work.
Playground: https://play.golang.org/p/tSHdjBhhAJ
What is the best way to assign 2 structs in this case apart from manually assigning each field?
This is not a duplicate of Assign struct with another struct since here, you're assigning a struct to another struct of the same type. However what I want is assigning two different structs having the same field names.