优化代码

This commit is contained in:
刘祥超
2022-12-13 18:08:50 +08:00
parent 96f8f7e925
commit 42d0d63cf4
2 changed files with 15 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ package conns
import (
"net"
"sort"
"sync"
"time"
)
@@ -126,5 +127,12 @@ func (this *Map) AllConns() []*ConnInfo {
result = append(result, connInfo)
}
}
// 按时间排序
sort.Slice(result, func(i, j int) bool {
// 创建时间越大Age越小
return result[i].CreatedAt > result[j].CreatedAt
})
return result
}