如果某个 struct 需要排序,则必须实现 sort.Interface 接口,提供 Len、Less、Swap 三个方法的实现,然后调用 sort.Sort()
type ByCarbonPriceDesc []model.AuctionTxList
func (a ByCarbonPriceDesc) Len() int { return len(a) }
func (a ByCarbonPriceDesc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByCarbonPriceDesc) Less(i, j int) bool { return a[i].CarbonPrice > a[j].CarbonPrice }