MCPcopy Create free account
hub / github.com/docker/cli / validateHostPort

Function validateHostPort

internal/registry/config.go:231–253  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

229}
230
231func validateHostPort(s string) error {
232 // Split host and port, and in case s can not be split, assume host only
233 host, port, err := net.SplitHostPort(s)
234 if err != nil {
235 host = s
236 port = ""
237 }
238 // If match against the `host:port` pattern fails,
239 // it might be `IPv6:port`, which will be captured by net.ParseIP(host)
240 if !validHostPortRegex().MatchString(s) && net.ParseIP(host) == nil {
241 return invalidParamf("invalid host %q", host)
242 }
243 if port != "" {
244 v, err := strconv.Atoi(port)
245 if err != nil {
246 return err
247 }
248 if v < 0 || v > 65535 {
249 return invalidParamf("invalid port %q", port)
250 }
251 }
252 return nil
253}
254
255// NewIndexInfo creates a new [registry.IndexInfo] or the given
256// repository-name, and detects whether the registry is considered

Callers 1

newServiceConfigFunction · 0.85

Calls 2

MatchStringMethod · 0.80
invalidParamfFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…