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

Method dialContext

dialer.go:341–380  ·  view source on GitHub ↗
(ctx context.Context, network string, addr string)

Source from the content-addressed store, hash-verified

339}
340
341func (d *Dialer) dialContext(ctx context.Context, network string, addr string) (net.Conn, error) {
342 address, err := lookupHost(ctx, addr, d.Resolver)
343 if err != nil {
344 return nil, fmt.Errorf("failed to resolve host: %w", err)
345 }
346
347 dial := d.DialFunc
348 if dial == nil {
349 dial = (&net.Dialer{
350 LocalAddr: d.LocalAddr,
351 DualStack: d.DualStack,
352 FallbackDelay: d.FallbackDelay,
353 KeepAlive: d.KeepAlive,
354 }).DialContext
355 }
356
357 conn, err := dial(ctx, network, address)
358 if err != nil {
359 return nil, fmt.Errorf("failed to open connection to %s: %w", address, err)
360 }
361
362 if d.TLS != nil {
363 c := d.TLS
364 // If no ServerName is set, infer the ServerName
365 // from the hostname we're connecting to.
366 if c.ServerName == "" {
367 c = d.TLS.Clone()
368 // Copied from tls.go in the standard library.
369 colonPos := strings.LastIndex(address, ":")
370 if colonPos == -1 {
371 colonPos = len(address)
372 }
373 hostname := address[:colonPos]
374 c.ServerName = hostname
375 }
376 return d.connectTLS(ctx, conn, c)
377 }
378
379 return conn, nil
380}
381
382// DefaultDialer is the default dialer used when none is specified.
383var DefaultDialer = &Dialer{

Callers 1

connectMethod · 0.95

Calls 2

connectTLSMethod · 0.95
lookupHostFunction · 0.85

Tested by

no test coverage detected