0

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
PRITI JHA
  • 9
  • 5
  • Hi PRITIJHA, if the linked duplicate doesn't answer your question please provide a comment, or update the question, with more details about your problem, including the *expected output*. – mkopriva Feb 17 '22 at 18:55

0 Answers0