Skip to content

net: lack of guidance on dialing and addresses #76774

@aclements

Description

@aclements

Go 1.26 introduces four more Dial functions in package net (#49097), which means we now have a complicated combination of old and new ways to represent addresses and dial. What are the best practices today? At a minimum, the documentation should give guidance on how to navigate this. Is there an opportunity for a modernizer to automatically drive code toward the latest best practices?

For dialing, we now have

func Dial(network, address string) (Conn, error)
func DialTimeout(network, address string, timeout time.Duration) (Conn, error)
func DialIP(network string, laddr, raddr *IPAddr) (*IPConn, error)
func DialTCP(network string, laddr, raddr *TCPAddr) (*TCPConn, error)
func DialUDP(network string, laddr, raddr *UDPAddr) (*UDPConn, error)
func DialUnix(network string, laddr, raddr *UnixAddr) (*UnixConn, error)
func (*Dialer) Dial(network, address string) (Conn, error)
func (*Dialer) DialContext(ctx context.Context, network, address string) (Conn, error)
func (*Dialer) DialIP(ctx context.Context, network string, laddr, raddr netip.Addr) (*IPConn, error)
func (*Dialer) DialTCP(ctx context.Context, network string, laddr, raddr netip.AddrPort) (*TCPConn, error)
func (*Dialer) DialUDP(ctx context.Context, network string, laddr, raddr netip.AddrPort) (*UDPConn, error)
func (*Dialer) DialUnix(ctx context.Context, network string, laddr, raddr *UnixAddr) (*UnixConn, error)

For addresses, we now have

string

// Package net
type Addr interface { ... }
type IP []byte
type IPAddr struct {IP; string}
type TCPAddr struct {IP; int; string}
type UDPAddr struct {IP; int; string}
type UnixAddr struct {string; string}

// Package net/netip
type Addr struct { ... }
type AddrPort struct { ... }

CC @rsc @neild @bradfitz

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions