I have two structs:
type A struct {
Field1 string
Field2 int
Field3 int
}
type B struct {
Field1 string
Field2 int
}
I want to convert a slice of []A data(aData
) to a slice of []B data (bData
).
What is the idiomatic way to do so?
What I tried is this:
var newItem B
var aData []A
var bData []B
aData = [{"bob", 3, 4}, {"mary", 5, 2}]
for i:=0 ; i < len(aData); i++ {
newItem = {aData[i].Field1, aData[i].Field2}
bData = append( bData, newItem )
}
But it gives:
syntax error: missing operand