@@ -7,24 +7,29 @@ import (
77 "net"
88 "strconv"
99 "strings"
10+
11+ "github.com/moby/moby/api/types/container"
1012)
1113
1214// PortBinding represents a binding between a Host IP address and a Host Port
13- type PortBinding struct {
14- // HostIP is the host IP Address
15- HostIP string `json:"HostIp"`
16- // HostPort is the host port number
17- HostPort string
18- }
15+ //
16+ // Deprecated: Use github.com/moby/moby/api/types/container.PortBinding instead.
17+ type PortBinding = container.PortBinding
1918
2019// PortMap is a collection of PortBinding indexed by Port
21- type PortMap map [Port ][]PortBinding
20+ //
21+ // Deprecated: Use github.com/moby/moby/api/types/container.PortMap instead.
22+ type PortMap = container.PortMap
2223
2324// PortSet is a collection of structs indexed by Port
24- type PortSet map [Port ]struct {}
25+ //
26+ // Deprecated: Use github.com/moby/moby/api/types/container.PortSet instead.
27+ type PortSet = container.PortSet
2528
2629// Port is a string containing port number and protocol in the format "80/tcp"
27- type Port string
30+ //
31+ // Deprecated: Use github.com/moby/moby/api/types/container.PortProto instead.
32+ type Port = container.PortProto
2833
2934// NewPort creates a new instance of a Port given a protocol and port number or port range
3035func NewPort (proto , portOrRange string ) (Port , error ) {
@@ -33,9 +38,9 @@ func NewPort(proto, portOrRange string) (Port, error) {
3338 return "" , err
3439 }
3540 if start == end {
36- return Port (fmt .Sprintf ("%d/%s" , start , proto )), nil
41+ return container . PortProto (fmt .Sprintf ("%d/%s" , start , proto )), nil
3742 }
38- return Port (fmt .Sprintf ("%d-%d/%s" , start , end , proto )), nil
43+ return container . PortProto (fmt .Sprintf ("%d-%d/%s" , start , end , proto )), nil
3944}
4045
4146// ParsePort parses the port number string and returns an int
@@ -59,39 +64,6 @@ func ParsePortRangeToInt(rawPort string) (startPort, endPort int, _ error) {
5964 return parsePortRange (rawPort )
6065}
6166
62- // Proto returns the protocol of a Port
63- func (p Port ) Proto () string {
64- _ , proto , _ := strings .Cut (string (p ), "/" )
65- if proto == "" {
66- proto = "tcp"
67- }
68- return proto
69- }
70-
71- // Port returns the port number of a Port
72- func (p Port ) Port () string {
73- port , _ , _ := strings .Cut (string (p ), "/" )
74- return port
75- }
76-
77- // Int returns the port number of a Port as an int. It assumes [Port]
78- // is valid, and returns 0 otherwise.
79- func (p Port ) Int () int {
80- // We don't need to check for an error because we're going to
81- // assume that any error would have been found, and reported, in [NewPort]
82- port , _ := parsePortNumber (p .Port ())
83- return port
84- }
85-
86- // Range returns the start/end port numbers of a Port range as ints
87- func (p Port ) Range () (int , int , error ) {
88- portRange := p .Port ()
89- if portRange == "" {
90- return 0 , 0 , nil
91- }
92- return parsePortRange (portRange )
93- }
94-
9567// SplitProtoPort splits a port(range) and protocol, formatted as "<portnum>/[<proto>]"
9668// "<startport-endport>/[<proto>]". It returns an empty string for both if
9769// no port(range) is provided. If a port(range) is provided, but no protocol,
0 commit comments