mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-14 10:10:42 -07:00
- Use 'Pair' again, but this time, the key is an int64 that the selected sort field will be casted to. We therefore have now only one type of sort. - Check validity of sort string early on. - Ensure that the ConnInfo's field used by the sort is not the value from 'client', but really the one that was used for the sort. - Added a test for sort by Idle time.
47 lines
853 B
Go
47 lines
853 B
Go
// Copyright 2013-2016 Apcera Inc. All rights reserved.
|
|
|
|
package server
|
|
|
|
// Helper types to sort by ConnInfo values
|
|
type SortOpt string
|
|
|
|
const (
|
|
byCid SortOpt = "cid"
|
|
bySubs = "subs"
|
|
byPending = "pending"
|
|
byOutMsgs = "msgs_to"
|
|
byInMsgs = "msgs_from"
|
|
byOutBytes = "bytes_to"
|
|
byInBytes = "bytes_from"
|
|
byLast = "last"
|
|
byIdle = "idle"
|
|
)
|
|
|
|
func (s SortOpt) IsValid() bool {
|
|
switch s {
|
|
case "", byCid, bySubs, byPending, byOutMsgs, byInMsgs, byOutBytes, byInBytes, byLast, byIdle:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
type Pair struct {
|
|
Key *client
|
|
Val int64
|
|
}
|
|
|
|
type Pairs []Pair
|
|
|
|
func (d Pairs) Len() int {
|
|
return len(d)
|
|
}
|
|
|
|
func (d Pairs) Swap(i, j int) {
|
|
d[i], d[j] = d[j], d[i]
|
|
}
|
|
|
|
func (d Pairs) Less(i, j int) bool {
|
|
return d[i].Val < d[j].Val
|
|
}
|