| We implement sort.Interface-Len,Less, andSwap- on our type so we can use thesortpackage’s
genericSortfunction.LenandSwapwill usually be similar across types andLesswill
hold the actual custom sorting logic. In our case we
want to sort in order of increasing string length, so
we uselen(s[i])andlen(s[j])here. | func (s ByLength) Len() int {
	return len(s)
}
func (s ByLength) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
func (s ByLength) Less(i, j int) bool {
	return len(s[i]) < len(s[j])
}
 | 
        
        
          | With all of this in place, we can now implement our
custom sort by casting the original fruitsslice toByLength, and then usesort.Sorton that typed
slice. | func main() {
	fruits := []string{"peach", "banana", "kiwi"}
	sort.Sort(ByLength(fruits))
	fmt.Println(fruits)
}
 |