github.com/annchain/OG@v0.0.9/p2p/dns/simple_aname.go (about)

     1  package dns
     2  
     3  import (
     4  	"errors"
     5  	"github.com/sirupsen/logrus"
     6  	"net"
     7  )
     8  
     9  func Lookup(domain string) (ip net.IP, err error) {
    10  	ips, err := net.LookupIP(domain)
    11  	if err != nil {
    12  		logrus.WithError(err).WithField("domain", domain).Warn("cound not resolve IP")
    13  		err = errors.New("could not resolve IP")
    14  		return
    15  	}
    16  	if len(ips) > 0 {
    17  		return ips[0], nil
    18  	}
    19  	logrus.WithError(err).WithField("domain", domain).Warn("resolving IP returns no result")
    20  
    21  	return nil, errors.New("resolving IP returns no result")
    22  }