network

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package network provides an interface for the standard library's network operations. This is defined in a separate package to avoid issues with circular imports.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Network

type Network interface {
	io.Closer
	// Hostname returns the hostname of the local machine.
	Hostname() (string, error)
	// InterfaceAddrs returns a list of the network interfaces addresses.
	InterfaceAddrs() ([]stdnet.Addr, error)
	// LookupHost looks up the given host using the local resolver. It returns a slice of that host's addresses.
	LookupHost(host string) ([]string, error)
	// Dial connects to the address on the named network.
	// Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), "udp", "udp4" (IPv4-only), "udp6" (IPv6-only).
	Dial(network, address string) (stdnet.Conn, error)
	// DialContext connects to the address on the named network using the provided context.
	DialContext(ctx context.Context, network, address string) (stdnet.Conn, error)
	// Listen listens for incoming connections on the network address.
	// Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only).
	// If the address is an empty string, Listen listens on all available addresses.
	Listen(network, address string) (stdnet.Listener, error)
	// ListenPacket listens for incoming packets addressed to the local address.
	// Known networks are "udp", "udp4" (IPv4-only), "udp6" (IPv6-only).
	// Caveat: The SetDeadline, SetReadDeadline, or SetWriteDeadline functions on the returned
	// PacketConn may not work as expected (due to gVisor issues).
	ListenPacket(network, address string) (stdnet.PacketConn, error)
}

Network is an interface that abstracts the standard library's network operations.

func Host

func Host() Network

Host returns a Network implementation that uses the standard library's network operations. This is used in integration testing to avoid needing to mock out WireGuard.

Jump to

Keyboard shortcuts

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