From 1fa7dcd832c3cbe9181c33fe5aff50d332fee706 Mon Sep 17 00:00:00 2001 From: Jeff Hodges Date: Wed, 5 Jul 2017 13:28:21 -0700 Subject: [PATCH] localhost hack for macOS 10.12.5 See https://github.com/bazelbuild/rules_webtesting/issues/150 and https://github.com/golang/go/issues/20904 --- go/httphelper/http_helper.go | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/go/httphelper/http_helper.go b/go/httphelper/http_helper.go index 18e3219b..2ec8808c 100644 --- a/go/httphelper/http_helper.go +++ b/go/httphelper/http_helper.go @@ -20,11 +20,8 @@ import ( "crypto/tls" "fmt" "io/ioutil" - "net" "net/http" "net/url" - "os" - "sort" "strings" ) @@ -123,32 +120,8 @@ func (s longestToShortest) Less(i, j int) bool { return len(s[i]) > len(s[j]) } -// FQDN returns the fully-qualified domain name (or localhost if lookup +// FQDN returns the fully-qualified domain name (or localhost if lookup // according to the hostname fails). func FQDN() (string, error) { - hostname, err := os.Hostname() - if err != nil { - // Fail if the kernel fails to report a hostname. - return "", err - } - - addrs, err := net.LookupHost(hostname) - if err != nil { - return "localhost", nil - } - - for _, addr := range addrs { - if names, err := net.LookupAddr(addr); err == nil && len(names) > 0 { - sort.Sort(longestToShortest(names)) - for _, name := range names { - name = strings.TrimRight(name, ".") - if strings.HasPrefix(name, hostname) { - return name, nil - } - } - return names[0], nil - } - } - return "localhost", nil }