This is a creation in Article, where the information may have evolved or changed.
Go has sort sorted packages that you can use directly, or you can use Func to customize
Here's an example
//****************************************************///copyright (c) Tencent, all rights reserved//File:sorting.go//Author:ningzhong.zeng//revision:2015-11-26 19:58:56//Description://****************************************************/Import("FMT" "Sort")//Custom Func sorttypeBylength []stringfunc(S Bylength) Len ()int{return Len(s)}func(S Bylength) Swap (I, Jint) {S[i], s[j] = S[j], S[i]}func(S Bylength) Less (I, Jint)BOOL{return Len(S[i]) <Len(S[j])}funcMain () {FMT. Println ("Start Main func ()") STRs: = []string{"a","D","L","P"} sort. Strings (STRs) fmt. Println ("STRs", STRs) INTs: = []int{3,6,8,5} sort. Ints (Ints) fmt. Println ("INTs", INTs)//Sort by funcFruits: = []string{"PE","BA","Ki"} sort. Sort (bylength (fruits)) fmt. Println ("Fruits", fruits)}//STRs [a D l p]//INTs [3 5 6 8]//fruits [pe ba ki]