// define a slice of integers nums := []int{4, 2, 5, 1, 3} // sort the slice using sort Interface sort.Ints(nums) // print the sorted slice fmt.Println(nums)
// define a slice of structs type Person struct { Name string Age int } people := []Person{ {"John", 21}, {"Jane", 20}, {"Jake", 25}, } // sort the slice of structs by age using sort Interface sort.Slice(people, func(i, j int) bool { return people[i].Age < people[j].Age }) // print the sorted slice of structs fmt.Println(people)This example sorts a slice of Person structs by age using the `sort.Slice` function from the sort package library in Go. Overall, the sort Interface is a powerful tool in Go that facilitates sorting collections of data in various ways. It is part of the standard library and hence does not require any external dependencies or packages.