I have the following Structs:
type Parent struct {
id string
children []Child
}
type Child struct {
id string
}
I have m
I got it to work using the following code:
// sort each Parent in the parents slice by Id
sort.Slice(parents, func(i, j int) bool {return parents[i].id < parents[j].id})
// for each Parent, sort each Child in the children slice by Id
for _, parent := range parents {
sort.Slice(parent.children, func(i, j int) bool {return parent.children[i].id < parent.children[j].id})
}
Special thanks to @Volker for mentioning the sort.Slice function! I had no idea it existed!