-
Notifications
You must be signed in to change notification settings - Fork 5
/
port.go
42 lines (35 loc) · 837 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
39
40
41
42
package service
import (
"fmt"
"strings"
"git.containerum.net/ch/kube-client/pkg/model"
)
type Port struct {
Name string
Port *int
TargetPort int
Protocol string
}
func (port Port) String() string {
p := fmt.Sprintf("%d", port.TargetPort)
if port.Port != nil {
p = fmt.Sprintf("%d:%d", port.TargetPort, *port.Port)
}
return fmt.Sprintf("%s %s/%s", port.Name, p, port.Protocol)
}
func PortFromKube(kubePort model.ServicePort) Port {
return Port{
Name: kubePort.Name,
Port: kubePort.Port,
TargetPort: kubePort.TargetPort,
Protocol: string(kubePort.Protocol),
}
}
type PortList []Port
func (list PortList) String() string {
ports := make([]string, 0, len(list))
for _, port := range list {
ports = append(ports, port.String())
}
return "[" + strings.Join(ports, ", ") + "]"
}