The net package provides a number of useful functions around DNS lookup. This information is comparable to what you might get from using the Unixdig command. This information can be extremely useful for you to implement any kind of network programming that requires dynamically determining IP addresses.
This recipe will explore how you might gather this data. To demonstrate this, we'll implement a simplified dig command. We'll seek to map a URL to all of its IPv4 and IPv6 addresses. By modifying GODEBUG=netdns= to be set to go or cgo, it will either use the pure Go DNS resolver or the cgo resolver. By default, the pure Go DNS resolver is used.
How to do it...
These steps cover writing and running your application:
- From your Terminal or console application, create a new directory called~/projects/go-programming-cookbook/chapter5/dnsand navigate to this directory.
- Run the following...