feat: 展示排序 close #29

This commit is contained in:
naiba
2021-01-08 21:04:50 +08:00
parent 35766e590d
commit 347bb7faa0
14 changed files with 63 additions and 42 deletions

View File

@@ -1,6 +1,7 @@
package dao
import (
"sort"
"sync"
"github.com/patrickmn/go-cache"
@@ -25,7 +26,8 @@ var Cache *cache.Cache
var DB *gorm.DB
// ServerList ..
var ServerList map[string]*model.Server
var ServerList map[uint64]*model.Server
var SortedServerList []*model.Server
// ServerLock ..
var ServerLock sync.RWMutex
@@ -39,6 +41,17 @@ func init() {
}
}
func ReSortServer() {
SortedServerList = []*model.Server{}
for _, s := range ServerList {
SortedServerList = append(SortedServerList, s)
}
sort.SliceStable(SortedServerList, func(i, j int) bool {
return SortedServerList[i].DisplayIndex > SortedServerList[j].DisplayIndex
})
}
// SendCommand ..
func SendCommand(cmd *pb.Command) {
ServerLock.RLock()