Suppose I have the following struct:
type X struct{
Name string
Age int
Email string
}
and then I have 2 other structs (subclasses):
type A struct{
*X
}
type B struct{
*X
}
Then in my main code I have:
a := A{&X{"John", 34, "jd@email.com"}}
b := B{&X{"Greg", 22, "gd@email.com"}}
fmt.Println(a.Name) // John
fmt.Println(b.Name) //Greg
Is there a simple way to assign a=b
such that a.Name
returns Greg
as well as all the other properties (I don't want to assign them individually because there's a bunch of properties)
Note: I have to do it this way as I have two identical database tables (in terms of their properties) and the ORM I'm using bases the target table on the struct name. Speaking of, I'm not sure how the ORM identifies the "structure" of the struct to perform this logic, but does using embedded fields, instead of standard fields affect this?