Documentation ¶
Overview ¶
Package dnscache is a Go package for caching DNS lookup results in memory. It asynchronously lookups DNS and refreshes results. The main motivation of this package is to avoid too much DNS lookups for every request (DNS lookup sometimes makes request really slow and causes error). This can be mainly used for the targets which are running on non-dynamic environment where IP does not change often.
Code was adopted from https://github.com/mercari/go-dnscache
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DialFunc ¶
func DialFunc(resolver *Resolver, baseDialFunc dialFunc) dialFunc
DialFunc is a helper function which returns `net.DialContext` function. It randomly fetches an IP from the DNS cache and dials it by the given dial function. It dials one by one and returns first connected `net.Conn`. If it fails to dial all IPs from cache it returns first error. If no baseDialFunc is given, it sets default dial function.
You can use returned dial function for `http.Transport.DialContext`.
In this function, it uses functions from `rand` package. To make it really random, you MUST call `rand.Seed` and change the value from the default in your application
Types ¶
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver is DNS cache resolver which cache DNS resolve results in memory.
func New ¶
New initializes DNS cache resolver and starts auto refreshing in a new goroutine. To stop refreshing, call `Stop()` function.
func (*Resolver) Fetch ¶
Fetch fetches IP list from the cache. If IP list of the given addr is not in the cache, then it lookups from DNS server by `Lookup` function.