networking

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package networking provides utilities for network operations, such as finding available ports and checking network connectivity.

Index

Constants

View Source
const (
	// MinPort is the minimum port number to use
	MinPort = 10000
	// MaxPort is the maximum port number to use
	MaxPort = 65535
	// MaxAttempts is the maximum number of attempts to find an available port
	MaxAttempts = 10
)
View Source
const (
	// ErrPrivateIpAddress is the error returned when the provided URL redirects to a private IP address
	ErrPrivateIpAddress = "the provided registry URL redirects to a private IP address, which is not allowed; " +
		"to override this, reset the registry URL using the --allow-private-ip (-p) flag"
)
View Source
const HttpTimeout = 30 * time.Second

HttpTimeout is the timeout for outgoing HTTP requests

Variables

This section is empty.

Functions

func AddressReferencesPrivateIp added in v0.1.1

func AddressReferencesPrivateIp(address string) error

AddressReferencesPrivateIp returns an error if the address references a private IP address

func FindAvailable

func FindAvailable() int

FindAvailable finds an available port

func FindOrUsePort

func FindOrUsePort(port int) (int, error)

FindOrUsePort checks if the provided port is available or finds an available port if none is provided. If port is 0, it will find an available port. If port is not 0, it will check if the port is available. Returns the selected port and an error if any.

func GetHttpClient added in v0.1.1

func GetHttpClient(allowPrivateIp bool) *http.Client

GetHttpClient returns a new http client which uses a protected dialer and URL validation by default

func IsAvailable

func IsAvailable(port int) bool

IsAvailable checks if a port is available

func IsIPv6Available

func IsIPv6Available() bool

IsIPv6Available checks if IPv6 is available on the system by looking for IPv6 addresses on network interfaces

Types

type ValidatingTransport added in v0.0.37

type ValidatingTransport struct {
	Transport http.RoundTripper
}

ValidatingTransport is for validating URLs prior to request

func (*ValidatingTransport) RoundTrip added in v0.0.37

func (t *ValidatingTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip validates the request URL prior to forwarding

Jump to

Keyboard shortcuts

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