| 我们为该类型实现了 sort.Interface接口的Len、Less和Swap方法,
这样我们就可以使用sort包的通用Sort方法了,Len和Swap在各个类型中的实现都差不多,Less将控制实际的自定义排序逻辑。
在这个的例子中,我们想按字符串长度递增的顺序来排序,
所以这里使用了len(s[i])和len(s[j])来实现Less。 | 
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])
}
 | 
        
        
          | 一切准备就绪后,我们就可以通过将切片 fruits强转为byLength类型的切片,
然后对该切片使用sort.Sort来实现自定义排序。 | 
func main() {
    fruits := []string{"peach", "banana", "kiwi"}
    sort.Sort(byLength(fruits))
    fmt.Println(fruits)
}
 |