spiegel_podman/cmd/podman/common/ports.go
Jhon Honce 22d5b2e305 V2 enable ps tests
* Combine cobra.Command helper functions into validate package
  from registry and common packages
* Introduce ChoiceValue for flags

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-04-29 15:51:37 -07:00

22 lines
684 B
Go

package common
import (
"github.com/docker/go-connections/nat"
"github.com/pkg/errors"
)
func verifyExpose(expose []string) error {
// add the expose ports from the user (--expose)
// can be single or a range
for _, expose := range expose {
// support two formats for expose, original format <portnum>/[<proto>] or <startport-endport>/[<proto>]
_, port := nat.SplitProtoPort(expose)
// parse the start and end port and create a sequence of ports to expose
// if expose a port, the start and end port are the same
_, _, err := nat.ParsePortRange(port)
if err != nil {
return errors.Wrapf(err, "invalid range format for --expose: %s", expose)
}
}
return nil
}