-
Notifications
You must be signed in to change notification settings - Fork 12
/
sort.go
87 lines (65 loc) · 1.83 KB
/
sort.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"sort"
"github.com/aws/aws-sdk-go/service/ecs"
)
// ClusterSlice attaches the Sort interface to ecs.Cluster
type ClusterSlice []*ecs.Cluster
func (s ClusterSlice) Len() int {
return len([]*ecs.Cluster(s))
}
func (s ClusterSlice) Less(i, j int) bool {
return string(*s[i].ClusterName) < string(*s[j].ClusterName)
}
func (s ClusterSlice) Swap(i, j int) {
s[j], s[i] = s[i], s[j]
}
// Sort is a convenience method for sorting clusters
func (s ClusterSlice) Sort() {
sort.Sort(s)
}
// ServiceSlice attaches the Sort interface to ecs.Service
type ServiceSlice []*ecs.Service
func (s ServiceSlice) Len() int {
return len([]*ecs.Service(s))
}
func (s ServiceSlice) Less(i, j int) bool {
return string(*s[i].ServiceName) < string(*s[j].ServiceName)
}
func (s ServiceSlice) Swap(i, j int) {
s[j], s[i] = s[i], s[j]
}
// Sort is a convenience method for sorting clusters
func (s ServiceSlice) Sort() {
sort.Sort(s)
}
// ServiceEventSlice attaches the Sort interface to ecs.ServiceEvent
type ServiceEventSlice []*ecs.ServiceEvent
func (s ServiceEventSlice) Len() int {
return len([]*ecs.ServiceEvent(s))
}
func (s ServiceEventSlice) Less(i, j int) bool {
return s[i].CreatedAt.Before(*s[j].CreatedAt)
}
func (s ServiceEventSlice) Swap(i, j int) {
s[j], s[i] = s[i], s[j]
}
// Sort is a convenience method for sorting clusters
func (s ServiceEventSlice) Sort() {
sort.Sort(s)
}
// KeyValuePairSlice attaches the Sort interface to ecs.KeyValuePair
type KeyValuePairSlice []*ecs.KeyValuePair
func (s KeyValuePairSlice) Len() int {
return len([]*ecs.KeyValuePair(s))
}
func (s KeyValuePairSlice) Less(i, j int) bool {
return *s[i].Name < *s[j].Name
}
func (s KeyValuePairSlice) Swap(i, j int) {
s[j], s[i] = s[i], s[j]
}
// Sort is a convenience method for sorting clusters
func (s KeyValuePairSlice) Sort() {
sort.Sort(s)
}