Skip to content

Commit d689c0d

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

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

nat/nat.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,15 @@ type PortSet map[Port]struct{}
2727
type Port string
2828

2929
// NewPort creates a new instance of a Port given a protocol and port number or port range
30-
func NewPort(proto, port string) (Port, error) {
31-
// Check for parsing issues on "port" now so we can avoid having
32-
// to check it later on.
33-
34-
portStartInt, portEndInt, err := ParsePortRangeToInt(port)
30+
func NewPort(proto, portOrRange string) (Port, error) {
31+
start, end, err := parsePortRange(portOrRange)
3532
if err != nil {
3633
return "", err
3734
}
38-
39-
if portStartInt == portEndInt {
40-
return Port(fmt.Sprintf("%d/%s", portStartInt, proto)), nil
35+
if start == end {
36+
return Port(fmt.Sprintf("%d/%s", start, proto)), nil
4137
}
42-
return Port(fmt.Sprintf("%d-%d/%s", portStartInt, portEndInt, proto)), nil
38+
return Port(fmt.Sprintf("%d-%d/%s", start, end, proto)), nil
4339
}
4440

4541
// ParsePort parses the port number string and returns an int

0 commit comments

Comments
 (0)