I have two structs A & B and a nested struct C with A & B, defined as below:
Struct A :
type Source_a struct{
Sname string
price float64
Qty int
}
Struct B :
type Source_b struct{
Sname2 string
price2 float64
Qty2 int
}
Nested Struct C :
type Data struct{
S_a []Source_a
S_b []Source_b
}
I have declared the Source_a & Source_b type var and derived & assigned the values to it from DB. Sample code for Struct A:
//Post DB query
sks := make([]Source_a, 0)
for rows.Next(){
sk := Source_a{}
err := rows.Scan(&sk.Sname, &sk.Uprice, &sk.Qty)
sks = append(sks, sk)
I am having trouble in binding the values of Struct A & B to Struct C. I am trying something but it is throwing errors, pretty sure this is not the correct way:
td := Data{
S_a: []Source_a{
Source_a{
Sname:sks.Sname,
Uprice:sks.Uprice,
Qty:sks.Qty,
},
},
S_b: []Source_b{
Source_b{
Sname2: sks2.Sname2,
Uprice2: sks2.Uprice2,
Qty2: sks2.Qty2,
},
},
},
Can you please help, I am new to Golang. Let me know if you need clarifications or specifics.