-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstruct.go
57 lines (47 loc) · 1.13 KB
/
struct.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
package kube
import (
"fmt"
"time"
)
type KubePod struct {
name string
restarts int32
age time.Duration
}
func NewKubePod(name string, restarts int32, age time.Duration) *KubePod {
return &KubePod{
name: name,
restarts: restarts,
age: age,
}
}
func (k *KubePod) String() string {
return fmt.Sprintf("Name: %s | Restarts: %d | Age: %d", k.name, k.restarts, k.age)
}
// name sorts
type sortKubeByName []KubePod
func (s sortKubeByName) Len() int { return len(s) }
func (s sortKubeByName) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s sortKubeByName) Less(i, j int) bool {
return s[i].name < s[j].name
}
// restart sorts
type sortKubeByRestarts []KubePod
func (s sortKubeByRestarts) Len() int { return len(s) }
func (s sortKubeByRestarts) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s sortKubeByRestarts) Less(i, j int) bool {
return s[i].restarts < s[j].restarts
}
// age sorts
type sortKubeByAge []KubePod
func (s sortKubeByAge) Len() int { return len(s) }
func (s sortKubeByAge) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s sortKubeByAge) Less(i, j int) bool {
return s[i].age < s[j].age
}