The 3 ways to sort in Go
* Sort a slice of ints, float64s or strings
* sort.Ints
* sort.Float64s
* sort.Strings
* Sort with custom comparator
* Use the function sort.Slice. It sorts a slice using a provided function less(i, j int) bool.
* To sort the slice while keeping the original order of equal elements, use sort.SliceStable instead.
* Sort custom data structures
* Use the generic sort.Sort and sort.Stable functions.
* They sort any collection that implements the sort.Interface interface.
```
package main
import (
"fmt"
"sort"
)
func sortNumber() {
v := []int{3, 2, 4, 1}
sort.Ints(v)
fmt.Println(v)
}
func sortSlice() {
v := []struct {
Name string
Age int
}{
{"Eve", 32},
{"Alice", 12},
{"Bob", 23},
}
sort.Slice(v, func(i int, j int) bool {
return v[i].Age < v[j].Age
})
fmt.Println(v)
}
func main() {
sortNumber()
sortSlice()
}
```