Skip to content

Commit 607e49d

Browse files
committed
Use github.com/moby/moby/api container network port defines
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
1 parent 3091246 commit 607e49d

File tree

3 files changed

+43
-46
lines changed

3 files changed

+43
-46
lines changed

go.mod

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ module github.com/docker/go-connections
22

33
go 1.23.0
44

5-
require github.com/Microsoft/go-winio v0.4.21
5+
require (
6+
github.com/Microsoft/go-winio v0.4.21
7+
github.com/moby/moby/api v1.52.0-alpha.1
8+
)
69

7-
require golang.org/x/sys v0.1.0 // indirect
10+
require (
11+
github.com/docker/go-units v0.5.0 // indirect
12+
github.com/moby/docker-image-spec v1.3.1 // indirect
13+
github.com/opencontainers/go-digest v1.0.0 // indirect
14+
github.com/opencontainers/image-spec v1.1.1 // indirect
15+
golang.org/x/sys v0.1.0 // indirect
16+
)
17+
18+
replace github.com/moby/moby/api v1.52.0-alpha.1 => github.com/austinvazquez/moby/api v1.52.0-alpha.1.0.20250813153006-f4e13e8ba3f2

go.sum

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
github.com/Microsoft/go-winio v0.4.21 h1:+6mVbXh4wPzUrl1COX9A+ZCvEpYsOBZ6/+kwDnvLyro=
22
github.com/Microsoft/go-winio v0.4.21/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
3+
github.com/austinvazquez/moby/api v1.52.0-alpha.1.0.20250813153006-f4e13e8ba3f2 h1:EK5ccZEz2/tILjbX3X8LhT+pxqm4b0gHGgcT02t5Ols=
4+
github.com/austinvazquez/moby/api v1.52.0-alpha.1.0.20250813153006-f4e13e8ba3f2/go.mod h1:TkzUa1zvG3KBha4OP8wIMidbZUf4bwG4OdlMaO6ZdWc=
35
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
7+
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
8+
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
9+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
10+
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
11+
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
12+
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
13+
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
14+
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
15+
github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=
416
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
517
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
618
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
@@ -9,3 +21,5 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7w
921
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1022
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
1123
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
24+
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
25+
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=

nat/nat.go

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -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
3035
func 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

Comments
 (0)