MCPcopy Index your code
hub / github.com/docker/cli / ValidateIPAddress

Function ValidateIPAddress

opts/opts.go:188–193  ·  view source on GitHub ↗

ValidateIPAddress validates if the given value is a correctly formatted IP address, and returns the value in normalized form. Leading and trailing whitespace is allowed, but it does not allow IPv6 addresses surrounded by square brackets ("[::1]"). Refer to [net.ParseIP] for accepted formats.

(val string)

Source from the content-addressed store, hash-verified

186//
187// Refer to [net.ParseIP] for accepted formats.
188func ValidateIPAddress(val string) (string, error) {
189 if ip := net.ParseIP(strings.TrimSpace(val)); ip != nil {
190 return ip.String(), nil
191 }
192 return "", fmt.Errorf("IP address is not correctly formatted: %s", val)
193}
194
195// ValidateMACAddress validates a MAC address.
196//

Callers 2

TestValidateIPAddressFunction · 0.85
ValidateExtraHostFunction · 0.85

Calls 1

StringMethod · 0.65

Tested by 1

TestValidateIPAddressFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…