Skip to content

Commit 2433ffa

Browse files
committed
nat: ParsePortSpec: reimplement with parsePortNumber
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent d689c0d commit 2433ffa

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

nat/nat.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,14 @@ func ParsePortSpec(rawPort string) ([]PortMapping, error) {
186186
return nil, fmt.Errorf("no port specified: %s<empty>", rawPort)
187187
}
188188

189-
startPort, endPort, err := ParsePortRange(containerPort)
189+
startPort, endPort, err := parsePortRange(containerPort)
190190
if err != nil {
191191
return nil, errors.New("invalid containerPort: " + containerPort)
192192
}
193193

194-
var startHostPort, endHostPort uint64
194+
var startHostPort, endHostPort int
195195
if hostPort != "" {
196-
startHostPort, endHostPort, err = ParsePortRange(hostPort)
196+
startHostPort, endHostPort, err = parsePortRange(hostPort)
197197
if err != nil {
198198
return nil, errors.New("invalid hostPort: " + hostPort)
199199
}
@@ -210,19 +210,18 @@ func ParsePortSpec(rawPort string) ([]PortMapping, error) {
210210
count := endPort - startPort + 1
211211
ports := make([]PortMapping, 0, count)
212212

213-
for i := uint64(0); i < count; i++ {
214-
cPort := Port(strconv.FormatUint(startPort+i, 10) + "/" + proto)
213+
for i := 0; i < count; i++ {
215214
hPort := ""
216215
if hostPort != "" {
217-
hPort = strconv.FormatUint(startHostPort+i, 10)
216+
hPort = strconv.Itoa(startHostPort + i)
218217
// Set hostPort to a range only if there is a single container port
219218
// and a dynamic host port.
220219
if count == 1 && startHostPort != endHostPort {
221-
hPort += "-" + strconv.FormatUint(endHostPort, 10)
220+
hPort += "-" + strconv.Itoa(endHostPort)
222221
}
223222
}
224223
ports = append(ports, PortMapping{
225-
Port: cPort,
224+
Port: Port(strconv.Itoa(startPort+i) + "/" + proto),
226225
Binding: PortBinding{HostIP: ip, HostPort: hPort},
227226
})
228227
}

0 commit comments

Comments
 (0)