netx

package
v1.104.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: BSD-3-Clause Imports: 6 Imported by: 4 modules, 6 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package netx contains types to describe and abstract over how dialing and listening are performed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RaceDial added in v1.100.0

func RaceDial(ctx context.Context, addrs []netip.AddrPort, dial DialFunc, fallbackDelay time.Duration) (net.Conn, error)

RaceDial races TCP connect attempts across addrs using a happy-eyeballs-style staggered approach: a new dial is started every fallbackDelay, and the first successful connection wins. Losers are cancelled and their connections closed. If all dials fail, the first error is returned.

Addresses are interleaved v6-first so that IPv6 is preferred but both families are tried promptly. The dial func is always called with network "tcp".

Types

type DialFunc

type DialFunc func(ctx context.Context, network, address string) (net.Conn, error)

DialFunc is a function that dials a network address.

It's the type implemented by net.Dialer.DialContext or required by net/http.Transport.DialContext, etc.

type Network

type Network interface {
	NewLocalTCPListener() net.Listener
	Listen(network, address string) (net.Listener, error)
	Dial(ctx context.Context, network, address string) (net.Conn, error)
}

Network describes a network that can listen and dial. The two common implementations are RealNetwork, using the net package to use the real network, or [memnet.Network], using an in-memory network (typically for testing)

func RealNetwork

func RealNetwork() Network

RealNetwork returns a Network implementation that uses the real net package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL