/
externalservice_helpers.go
67 lines (58 loc) 路 1.16 KB
/
externalservice_helpers.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
package v1alpha1
import (
"net"
"strconv"
)
// Matches is simply an alias for MatchTags to make source code more aesthetic.
func (es *ExternalService) Matches(selector TagSelector) bool {
if es != nil {
return es.MatchTags(selector)
}
return false
}
func (es *ExternalService) MatchTags(selector TagSelector) bool {
return selector.Matches(es.Tags)
}
func (es *ExternalService) GetService() string {
if es == nil {
return ""
}
return es.Tags[ServiceTag]
}
func (es *ExternalService) GetProtocol() string {
if es == nil {
return ""
}
return es.Tags[ProtocolTag]
}
func (es *ExternalService) GetHost() string {
if es == nil {
return ""
}
host, _, err := net.SplitHostPort(es.Networking.Address)
if err != nil {
return ""
}
return host
}
func (es *ExternalService) GetPort() string {
if es == nil {
return ""
}
_, port, err := net.SplitHostPort(es.Networking.Address)
if err != nil {
return ""
}
return port
}
func (es *ExternalService) GetPortUInt32() uint32 {
port := es.GetPort()
iport, err := strconv.Atoi(port)
if err != nil {
return 0
}
return uint32(iport)
}
func (es *ExternalService) TagSet() SingleValueTagSet {
return es.Tags
}