here are my initial model
type Team struct {
Id string `json:"id"`
Name string `json:"name"`
Level int64 `json:"level"`
}
type TeamTree struct {
Teams []Team `json:"teams"`
Child []TeamTree `json:"child"`
}
Sample data:
id team level
a BOD 1
b Marketing 2
c Dev 2
d Worker 3
I want to have this result (should be a mapping):
{
"teams": [
{"id": "a", "team": "BOD", "level": 1}
],
"child": {
"teams": [
{"id":"b", "team": "marketing", "level": 2},
{"id":"c", "team": "marketing", "level": 2}
],
"child": {
"teams": [
{"id": "d", "team": "worker", "level": 3}
],
"child"": {}
}
}
}
I was told to do self loop, but I do not know how to do it, since I keep getting error and my code cant even run.