netutil

package
v0.5.16 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MPL-2.0 Imports: 7 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultDNSCache = &SimpleDNSCache{}

Functions

func LookupReachable

func LookupReachable(addr string, timeout time.Duration) (string, error)

LookupReachable tries to resolve addr via connecting to it. This method has much more overhead, but get guaranteed reachable resolved addr. Example: host is resolved to IPv4 and IPv6, but IPv4 is not working on machine. LookupReachable will return IPv6 in that case.

func ValidHTTPMethod added in v0.5.5

func ValidHTTPMethod(method string) bool

ValidHTTPMethod just copy net/http/request.go validMethod(method string) bool

func WarmDNSCache

func WarmDNSCache(c DNSCache, addr string) error

WarmDNSCache tries connect to addr, and adds conn remote ip + addr port to cache.

Types

type DNSCache

type DNSCache interface {
	Get(addr string) (string, bool)
	Add(addr, resolved string)
}

type Dialer

type Dialer interface {
	DialContext(ctx context.Context, net, addr string) (net.Conn, error)
}

type DialerFunc

type DialerFunc func(ctx context.Context, network, address string) (net.Conn, error)

func NewDNSCachingDialer

func NewDNSCachingDialer(dialer Dialer, cache DNSCache) DialerFunc

NewDNSCachingDialer returns dialer with primitive DNS caching logic that remembers remote address on first try, and use it in future.

func (DialerFunc) DialContext

func (f DialerFunc) DialContext(ctx context.Context, network, address string) (net.Conn, error)

type SimpleDNSCache

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

func (*SimpleDNSCache) Add

func (c *SimpleDNSCache) Add(addr, resolved string)

func (*SimpleDNSCache) Get

func (c *SimpleDNSCache) Get(addr string) (resolved string, ok bool)

Directories

Path Synopsis
Code generated by mockery v1.0.0
Code generated by mockery v1.0.0

Jump to

Keyboard shortcuts

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