netutil

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2022 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Addr

func Addr(addr net.Addr) net.Addr

Addr prepares a net.Addr to be used with HostPort and ignores any error.

func Host

func Host(addr net.Addr) string

Host is like HostPort, but directly returns the result of HostPortAddr.Host().

func NewAddr

func NewAddr(network, host string, port uint16) net.Addr

NewAddr returns a new net.Addr ready to use with HostPort.

func Parse

func Parse(addr string, network string) (net.Addr, error)

Parse parses addr and constructs a net.Addr compatible with HostPort.

func Port

func Port(addr net.Addr) uint16

Port is like HostPort, but directly returns the result of HostPortAddr.Port().

func WrapAddr

func WrapAddr(addr net.Addr) (net.Addr, error)

WrapAddr prepares a net.Addr to be used with HostPort.

func WrapConn

func WrapConn(conn net.Conn) (net.Conn, error)

WrapConn adds HostPortAddr to RemoteAddr and LocalAddr of the passed net.Conn such that using HostPort(conn.RemoteAddr()) returns the prepared HostPortAddr. Wrapping a net.Conn is useful when it is expected that HostPort is used often.

Types

type HostPortAddr

type HostPortAddr interface {
	// Host returns the host part from the address.
	Host() string
	// Port returns the port part from the address.
	// Zero value means the port is unspecified.
	Port() uint16
}

HostPortAddr provides the host and port of an address in cases where use of host, port, err := net.SplitHostPort(addressString) is too much and an error is unexpected or ignored.

func HostPort

func HostPort(addr net.Addr) HostPortAddr

HostPort is like Addr, but directly returns it's HostPortAddr.

Jump to

Keyboard shortcuts

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