-
Notifications
You must be signed in to change notification settings - Fork 474
/
port.go
38 lines (32 loc) · 824 Bytes
/
port.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
package models
import core_v1 "k8s.io/api/core/v1"
type Ports []Port
type Port struct {
Name string `json:"name"`
Protocol string `json:"protocol"`
Port int32 `json:"port"`
}
func (ports *Ports) Parse(ps []core_v1.ServicePort) {
for _, servicePort := range ps {
port := Port{}
port.Parse(servicePort)
*ports = append(*ports, port)
}
}
func (port *Port) Parse(p core_v1.ServicePort) {
port.Name = p.Name
port.Protocol = string(p.Protocol)
port.Port = p.Port
}
func (ports *Ports) ParseEndpointPorts(ps []core_v1.EndpointPort) {
for _, endpointPort := range ps {
port := Port{}
port.ParseEndpointPort(endpointPort)
*ports = append(*ports, port)
}
}
func (port *Port) ParseEndpointPort(p core_v1.EndpointPort) {
port.Name = p.Name
port.Protocol = string(p.Protocol)
port.Port = p.Port
}