-
Notifications
You must be signed in to change notification settings - Fork 1
/
statussort.go
67 lines (51 loc) · 1.7 KB
/
statussort.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
type deviceStatuses []deviceStatus
func (a deviceStatuses) Len() int { return len(a) }
func (a deviceStatuses) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
type byZoneName struct{ deviceStatuses }
func (a byZoneName) Less(i, j int) bool {
if a.deviceStatuses[i].ZoneName == a.deviceStatuses[j].ZoneName {
return byRackName(a).Less(i, j)
}
return a.deviceStatuses[i].ZoneName < a.deviceStatuses[j].ZoneName
}
type byRackName struct{ deviceStatuses }
func (a byRackName) Less(i, j int) bool {
if a.deviceStatuses[i].RackName == a.deviceStatuses[j].RackName {
return byHostname(a).Less(i, j)
}
return a.deviceStatuses[i].RackName < a.deviceStatuses[j].RackName
}
type byHostname struct{ deviceStatuses }
func (a byHostname) Less(i, j int) bool {
if a.deviceStatuses[i].Hostname == a.deviceStatuses[j].Hostname {
return byDevID(a).Less(i, j)
}
return a.deviceStatuses[i].Hostname < a.deviceStatuses[j].Hostname
}
type byDevID struct{ deviceStatuses }
func (a byDevID) Less(i, j int) bool { return a.deviceStatuses[i].Devid < a.deviceStatuses[j].Devid }
type bySize struct{ deviceStatuses }
func (a bySize) Less(i, j int) bool {
t1, t2 := a.deviceStatuses[i].BytesTotal, a.deviceStatuses[j].BytesTotal
if t1 == nil || t2 == nil {
return false
}
return *t1 < *t2
}
type byUsed struct{ deviceStatuses }
func (a byUsed) Less(i, j int) bool {
t1, t2 := a.deviceStatuses[i].BytesUsed, a.deviceStatuses[j].BytesUsed
if t1 == nil || t2 == nil {
return false
}
return *t1 < *t2
}
type byFree struct{ deviceStatuses }
func (a byFree) Less(i, j int) bool {
t1, t2 := a.deviceStatuses[i].BytesFree, a.deviceStatuses[j].BytesFree
if t1 == nil || t2 == nil {
return false
}
return *t1 < *t2
}