I have the following Structs:
type Parent struct {
id string
children []Child
}
type Child struct {
id string
}
I have made a slice of Parents with the following values:
parents := make([]Parent, 0)
p1 := Parent {
"3",
[]Child {
{"2"},
{"3"},
{"1"},
},
}
p2 := Parent {
"1",
[]Child {
{"8"},
{"9"},
{"7"},
},
}
p3 := Parent {
"2",
[]Child {
{"5"},
{"6"},
{"4"},
},
}
parents = append(parents, p1, p2, p3)
I am trying to sort the "parents" slice in the following order:
1) First, sort all Parents by Parent.id
2) Next, sort each Parent's "children" slice by Child.id
The expected result is something like:
[{1 [{7} {8} {9}]} {2 [{4} {5} {6}]} {3 [{1} {2} {3}]}]
Is there a way to do this in Go?