sud

package module
v0.0.0-...-f31c13b Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: GPL-3.0 Imports: 5 Imported by: 1

README

Single Use Dialer

GoDoc Build Status codecov

The sud Go package provides Single Use Dialers.

A single use dialer allows injecting a pre-established net.Conn into components that expect to control dialing themselves, such as http.Transport. The first dial succeeds and returns the injected connection; subsequent dials fail with ErrNoConnReuse.

The name "sud" is an acronym for "Single Use Dialer" (and also means "south" in Italian, which is a nice coincidence).

Usage

import "github.com/bassosimone/sud"

// Create a dialer wrapping an existing connection
conn, _ := net.Dial("tcp", "example.com:443")
dialer := sud.NewSingleUseDialer(conn)

// Use with http.Transport
transport := &http.Transport{
    DialContext: dialer.DialContext,
}

Installation

To add this package as a dependency to your module:

go get github.com/bassosimone/sud

Development

To run the tests:

go test -v .

To measure test coverage:

go test -v -cover .

License

SPDX-License-Identifier: GPL-3.0-or-later

History

Adapted from ooni/probe-cli.

Documentation

Overview

Package sud provides Single Use Dialers.

A single use dialer allows injecting a pre-established net.Conn into components that expect to control dialing themselves, such as [http.Transport]. The first dial succeeds and returns the injected connection; subsequent dials fail with ErrNoConnReuse.

The name "sud" is an acronym for "Single Use Dialer" (and also means "south" in Italian, which is a nice coincidence).

Index

Constants

This section is empty.

Variables

View Source
var ErrNoConnReuse = errors.New("cannot reuse connection")

ErrNoConnReuse is the type of error returned when you create a *SingleUseDialer and you dial more than once.

Functions

This section is empty.

Types

type SingleUseDialer

type SingleUseDialer struct {
	// contains filtered or unexported fields
}

SingleUseDialer is the Dialer returned by NewSingleUseDialer.

func NewSingleUseDialer

func NewSingleUseDialer(conn net.Conn) *SingleUseDialer

NewSingleUseDialer returns a "single use" dialer. The first dial will succeed and return the net.Conn regardless of the arguments passed to the dialing functions. Subsequent dial returns ErrNoConnReuse.

func (*SingleUseDialer) DialContext

func (sud *SingleUseDialer) DialContext(ctx context.Context, network string, addr string) (net.Conn, error)

DialContext dials once with the configured connection and then returns ErrNoConnReuse.

This method signature is compatible with the net/http package.

All arguments are ignored and we return the connection (once) or ErrNoConnReuse.

func (*SingleUseDialer) DialTLSContext

func (d *SingleUseDialer) DialTLSContext(
	ctx context.Context, network, address string, cfg *tls.Config) (net.Conn, error)

DialTLSContext dials once with the configured connection and then returns ErrNoConnReuse.

This method signature is compatible with the golang.org/x/net/http2 package.

All arguments are ignored and we return the connection (once) or ErrNoConnReuse.

Jump to

Keyboard shortcuts

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