...
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package format
15
16 import (
17 "bytes"
18 "net"
19 "strconv"
20 "time"
21
22 "github.com/prometheus/alertmanager/api/v2/models"
23 )
24
25 type ByEndAt []models.GettableSilence
26
27 func (s ByEndAt) Len() int { return len(s) }
28 func (s ByEndAt) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
29 func (s ByEndAt) Less(i, j int) bool {
30 return time.Time(*s[i].Silence.EndsAt).Before(time.Time(*s[j].Silence.EndsAt))
31 }
32
33 type ByStartsAt []*models.GettableAlert
34
35 func (s ByStartsAt) Len() int { return len(s) }
36 func (s ByStartsAt) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
37 func (s ByStartsAt) Less(i, j int) bool {
38 return time.Time(*s[i].StartsAt).Before(time.Time(*s[j].StartsAt))
39 }
40
41 type ByAddress []*models.PeerStatus
42
43 func (s ByAddress) Len() int { return len(s) }
44 func (s ByAddress) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
45 func (s ByAddress) Less(i, j int) bool {
46 ip1, port1, _ := net.SplitHostPort(*s[i].Address)
47 ip2, port2, _ := net.SplitHostPort(*s[j].Address)
48 if ip1 == ip2 {
49 p1, _ := strconv.Atoi(port1)
50 p2, _ := strconv.Atoi(port2)
51 return p1 < p2
52 }
53 return bytes.Compare(net.ParseIP(ip1), net.ParseIP(ip2)) < 0
54 }
55
View as plain text