//自定义结构体,用来自定义排序
type RecentlyUpdateListMapSorter []map[string]interface{}
//根据MapSorter.Keys进行倒序排序
func (ms *RecentlyUpdateListMapSorter) SortReverse() {
sort.Sort(sort.Reverse(ms))
}
//自定义排序方法(Len(),Less(),Swap())
func (ms *RecentlyUpdateListMapSorter) Len() int {
return len(*ms)
}
func (ms *RecentlyUpdateListMapSorter) Less(i, j int) bool {
t1, _ := time.Parse(timex.Layout_Normal, core.ToString((*ms)[i]["UpdateTime"]))
t2, _ := time.Parse(timex.Layout_Normal, core.ToString((*ms)[j]["UpdateTime"]))
return t1.Before(t2)
}
func (ms *RecentlyUpdateListMapSorter) Swap(i, j int) {
(*ms)[i], (*ms)[j] = (*ms)[j], (*ms)[i]
}
golang Map进行键值自定义排序
最新推荐文章于 2025-04-22 13:30:00 发布