-
Notifications
You must be signed in to change notification settings - Fork 2
/
type.go
126 lines (107 loc) · 3.35 KB
/
type.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package eureka
import (
"encoding/xml"
"strings"
"time"
)
type Instance struct {
XMLName xml.Name `xml:"instance"`
ID string `xml:"instanceId"`
HostName string `xml:"hostName"`
AppName string `xml:"app"`
IPAddr string `xml:"ipAddr"`
VIPAddr string `xml:"vipAddress"`
SecureVIPAddr string `xml:"secureVipAddress"`
Status Status `xml:"status"`
StatusOverride Status `xml:"overriddenstatus"`
Port Port `xml:"port"`
SecurePort Port `xml:"securePort"`
HomePageURL string `xml:"homePageUrl"`
StatusPageURL string `xml:"statusPageUrl"`
HealthCheckURL string `xml:"healthCheckUrl"`
DataCenterInfo DataCenter `xml:"dataCenterInfo"`
LeaseInfo Lease `xml:"leaseInfo"`
Metadata Metadata `xml:"metadata"`
}
// Equals checks if two instances are the same. Does not compare LeaseInfo.
func (i *Instance) Equals(other *Instance) bool {
return i.ID == other.ID &&
i.HostName == other.HostName &&
strings.ToUpper(i.AppName) == strings.ToUpper(other.AppName) &&
i.IPAddr == other.IPAddr &&
i.VIPAddr == other.VIPAddr &&
i.SecureVIPAddr == other.SecureVIPAddr &&
i.Status == other.Status &&
i.StatusOverride == other.StatusOverride &&
i.Port == other.Port &&
i.SecurePort == other.SecurePort &&
i.HomePageURL == other.HomePageURL &&
i.StatusPageURL == other.StatusPageURL &&
i.HealthCheckURL == other.HealthCheckURL &&
i.DataCenterInfo == other.DataCenterInfo &&
i.Metadata.Equals(other.Metadata)
}
type Port uint16
type Status uint8
const (
StatusUp Status = iota
StatusDown
StatusStarting
StatusOutOfService
StatusUnknown
)
type DataCenter struct {
Type DataCenterType `xml:"name"`
Metadata AmazonMetadata `xml:"metadata"`
}
type DataCenterType uint8
const (
DataCenterTypePrivate DataCenterType = iota
DataCenterTypeAmazon
)
type AmazonMetadata struct {
HostName string `xml:"hostname"`
PublicHostName string `xml:"public-hostname"`
LocalHostName string `xml:"local-hostname"`
PublicIPV4 string `xml:"public-ipv4"`
LocalIPV4 string `xml:"local-ipv4"`
AvailabilityZone string `xml:"availability-zone"`
InstanceID string `xml:"instance-id"`
InstanceType string `xml:"instance-type"`
AmiID string `xml:"ami-id"`
AmiLaunchIndex string `xml:"ami-launch-index"`
AmiManifestPath string `xml:"ami-manifest-path"`
}
type Lease struct {
RenewalInterval Duration `xml:"renewalIntervalInSecs"`
Duration Duration `xml:"durationInSecs"`
RegistrationTime Time `xml:"registrationTimestamp"`
LastRenewalTime Time `xml:"lastRenewalTimestamp"`
EvictionTime Time `xml:"evictionTimestamp"`
ServiceUpTime Time `xml:"serviceUpTimestamp"`
}
type Duration time.Duration
type Time time.Time
type Metadata map[string]string
func (m Metadata) Equals(other Metadata) bool {
if len(m) != len(other) {
return false
}
for k, v := range m {
if v != other[k] {
return false
}
}
return true
}
type App struct {
XMLName xml.Name `xml:"application"`
Name string `xml:"name"`
Instances []*Instance `xml:"instance"`
}
type AppsResponse struct {
XMLName xml.Name `xml:"applications"`
VersionDelta int `xml:"versions__delta"`
Hashcode string `xml:"apps__hashcode"`
Apps []*App `xml:"application"`
}