优化代码

This commit is contained in:
GoEdgeLab
2022-12-13 18:08:50 +08:00
parent 595a118cf2
commit c3cdfc2e44
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
}