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 accounts


num := []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}
posted @ 2018-06-06 11:02  黑手党老k  阅读(...)  评论(... 编辑 收藏