golang struct裏面的字段,或者slice排序

accounts := []users.Account{}Admin.DB.Preload("CurrencyObj").Where("member_id = ?", record.(*users.Member).ID).Find(&accounts)sort.Slice(accounts, func(i int, j int) bool {   return accounts[i].Balance > accounts[j].Balance})return accountsnum := []int{5,3,1,8,4,2}slice.Sort(num, func(i int, j int) bool {   return  num[i] < num[j]}fmt.Printf("%v\n", num) //  --> []int{1, 2, 3, 4, 5, 8}
相關文章
相關標籤/搜索