Reputation: 7859
I'm trying to initialize an embedded struct. However the compiler says I can't mix values and and value initializers. What's the correct syntax ?
httpCl is of type *requests.Trans
type clTran struct {
*requests.Trans
uCh chan user
}
func main() {
httpCl, err := requests.tr(px)
clT := clTran{httpCl, uCh: uCh}
}
Upvotes: 2
Views: 691
Reputation: 22236
If you label fields in a struct literal (which you usually should) all of them need to be labeled. In the case of embedding, the field takes the name of its type. So
clT := clTran {
Trans: httpCl,
uCh: uCh,
}
Note that this field name applies to accessing and writing too, clT.Trans = httpCl
is valid and will write to the embedded field.
Upvotes: 4