This question already has an answer here:
- Sorting by time.Time in Golang 3 answers
This answer here Sorting by time.Time in Golang
tries to sort with a secondary array with a map
type timeSlice []reviews_data
Can golang slices of objects with dates be sorted by without creating this secondary data structure?
Given a struct like
type SortDateExample struct {
sortByThis time.Time
id string
}
And a slice initialized something like
var datearray = var alerts = make([]SortDateExample, 0)
dateSlice = append(dateSlice,newSortDateExmple)
dateSlice = append(dateSlice,newSortDateExmple2)
dateSlice = append(dateSlice,newSortDateExmple3)
How can I sort array by the time field sortByThis?
</div>