Custom DNS Resolver for http.Client possible?

Is it possible to Go to http.Client to override the DNS Resolver, putting your local or any other? And if so, how to do it?

For example in Java (using apache http client) is as follows:

DnsResolver dnsResolver = new CustomDnsResolver();
...
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(
socketFactoryRegistry, connFactory, dnsResolver);
...
CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm);
September 18th 19 at 23:50
1 answer
September 18th 19 at 23:52
Solution
Never did, but if you already have the code for the resolver (which in name throws IP), no problems seen...

As it is written in https://golang.org/pkg/net/http/ “For control over proxies, TLS configuration, keep-alives, compression, and other settings, create a Transport”.

In your case you need to create eksemplar http.Transport with your own function Dial:
Dial func(network, addr string) (net.Conn, error)

In this function you received the host in parameter “addr”, rezolvate it themselves, and then call the standard net.Dial, but not with the host, and outresolving IP address. And then make http.Client with this transport:
client := &http.Client{Transport: tr}
and use it as usual.
Yes, you are absolutely right. - karina59 commented on September 18th 19 at 23:55

Find more questions by tags Computer networksGo