MCPcopy Create free account
hub / github.com/cortexproject/cortex / parseDockerIPv4Port

Function parseDockerIPv4Port

integration/e2e/service.go:711–730  ·  view source on GitHub ↗

parseDockerIPv4Port parses the input string which is expected to be the output of "docker port" command and returns the first IPv4 port found.

(out string)

Source from the content-addressed store, hash-verified

709// parseDockerIPv4Port parses the input string which is expected to be the output of "docker port"
710// command and returns the first IPv4 port found.
711func parseDockerIPv4Port(out string) (int, error) {
712 // The "docker port" output may be multiple lines if both IPv4 and IPv6 are supported,
713 // so we need to parse each line.
714 for line := range strings.SplitSeq(out, "\n") {
715 matches := dockerIPv4PortPattern.FindStringSubmatch(strings.TrimSpace(line))
716 if len(matches) != 2 {
717 continue
718 }
719
720 port, err := strconv.Atoi(matches[1])
721 if err != nil {
722 continue
723 }
724
725 return port, nil
726 }
727
728 // We've not been able to parse the output format.
729 return 0, errors.New("unknown output format")
730}

Callers 2

TestParseDockerPortFunction · 0.85
StartMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestParseDockerPortFunction · 0.68