How can I inject A and B's selected values into children C below?
decoder.go (Playground link)
package main
import (
"fmt"
)
type Input struct {
A []A
}
type A struct {
AID int
B []B
}
type B struct {
BID int
C []C
}
type C struct {
// I want to inject only AID and BID here
// But, without injecting A and B directly
// (without recursively)
CID int
}
func main() {
res := Input{
A: []A {
A {
AID: 1,
B: []B {
B{ BID: 11, C: []C{{ 111 }, { 111 }}},
B{ BID: 12, C: []C{{ 121 }, { 122 }}},
},
},
A {
AID: 2,
B: []B {
B{ BID: 21, C: []C{{ 211 }, { 211 }}},
B{ BID: 22, C: []C{{ 221 }, { 222 }}},
},
},
},
}
// I want to inject AID and BID into C
// WITHOUT nested loops like this:
for _, a := range res.A {
for _, b := range a.B {
for _, c := range b.C {
fmt.Println(a.AID, b.BID, c.CID)
}
}
}
}