@@ -23,8 +23,10 @@ type Endpoint struct {
23
23
Attributes map [string ]string
24
24
}
25
25
26
- const ipv4Attr = "AWS_INSTANCE_IPV4"
27
- const portAttr = "AWS_INSTANCE_PORT"
26
+ const (
27
+ Ipv4Attr = "AWS_INSTANCE_IPV4"
28
+ PortAttr = "AWS_INSTANCE_PORT"
29
+ )
28
30
29
31
// NewEndpointFromInstance converts a Cloud Map InstanceSummary to an endpoint
30
32
func NewEndpointFromInstance (inst * types.InstanceSummary ) (* Endpoint , error ) {
@@ -33,14 +35,14 @@ func NewEndpointFromInstance(inst *types.InstanceSummary) (*Endpoint, error) {
33
35
Attributes : make (map [string ]string , 0 ),
34
36
}
35
37
36
- if ipv4 , hasIp := inst .Attributes [ipv4Attr ]; hasIp {
38
+ if ipv4 , hasIp := inst .Attributes [Ipv4Attr ]; hasIp {
37
39
endpoint .IP = ipv4
38
40
} else {
39
41
return nil , errors .New (fmt .Sprintf ("cannot convert service instance %s to endpoint without IP address" , * inst .Id ))
40
42
}
41
43
42
- if portStr , hasPort := inst .Attributes [portAttr ]; hasPort {
43
- port , parseError := strconv .Atoi (portStr )
44
+ if portStr , hasPort := inst .Attributes [PortAttr ]; hasPort {
45
+ port , parseError := strconv .ParseUint (portStr , 10 , 16 )
44
46
45
47
if parseError != nil {
46
48
return nil , parseError
@@ -52,7 +54,7 @@ func NewEndpointFromInstance(inst *types.InstanceSummary) (*Endpoint, error) {
52
54
}
53
55
54
56
for key , val := range inst .Attributes {
55
- if key != ipv4Attr && key != portAttr {
57
+ if key != Ipv4Attr && key != PortAttr {
56
58
endpoint .Attributes [key ] = val
57
59
}
58
60
}
@@ -64,10 +66,10 @@ func NewEndpointFromInstance(inst *types.InstanceSummary) (*Endpoint, error) {
64
66
func (e * Endpoint ) GetAttributes () map [string ]string {
65
67
attrs := make (map [string ]string , 0 )
66
68
67
- attrs [ipv4Attr ] = e .IP
69
+ attrs [Ipv4Attr ] = e .IP
68
70
69
71
port := strconv .FormatInt (int64 (e .Port ), 10 )
70
- attrs [portAttr ] = port
72
+ attrs [PortAttr ] = port
71
73
72
74
for key , val := range e .Attributes {
73
75
attrs [key ] = val
0 commit comments