MCPcopy
hub / github.com/segmentio/kafka-go / lookupHost

Function lookupHost

dialer.go:467–493  ·  view source on GitHub ↗
(ctx context.Context, address string, resolver Resolver)

Source from the content-addressed store, hash-verified

465}
466
467func lookupHost(ctx context.Context, address string, resolver Resolver) (string, error) {
468 host, port := splitHostPort(address)
469
470 if resolver != nil {
471 resolved, err := resolver.LookupHost(ctx, host)
472 if err != nil {
473 return "", fmt.Errorf("failed to resolve host %s: %w", host, err)
474 }
475
476 // if the resolver doesn't return anything, we'll fall back on the provided
477 // address instead
478 if len(resolved) > 0 {
479 resolvedHost, resolvedPort := splitHostPort(resolved[0])
480
481 // we'll always prefer the resolved host
482 host = resolvedHost
483
484 // in the case of port though, the provided address takes priority, and we
485 // only use the resolved address to set the port when not specified
486 if port == "" {
487 port = resolvedPort
488 }
489 }
490 }
491
492 return net.JoinHostPort(host, port), nil
493}

Callers 2

dialContextMethod · 0.85
NewWriterFunction · 0.85

Calls 2

splitHostPortFunction · 0.85
LookupHostMethod · 0.65

Tested by

no test coverage detected