I am new to golang and surfing through various dns resolution method for golang and stuck with the error for net package.Below is a simple application which need to print IP addr but throws an error as no such host.
package main
import (
"fmt"
"net"
"os"
)
func main() {
name, err := os.Hostname()
fmt.Println("Name: ", name)
fmt.Print("Error: ", err)
addr, err := net.LookupIP(name)
fmt.Println("\nIP:", addr)
fmt.Println("Error:-", err)
}
I tried using options like export GODEBUG=netdns=go, export GODEBUG=netdns=cgo but nothing works.I am using mac and noticed that problem occurs on net.LookupIP(name).
Output of the code is:
Name: MacBook-Air.local
Error: <nil>
IP: []
Error:- lookup MacBook-Air.local: no such host