Skip to content

Commit

Permalink
localhost hack for macOS 10.12.5
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhodges committed Jan 27, 2018
1 parent 980c8ab commit 1fa7dcd
Showing 1 changed file with 1 addition and 28 deletions.
29 changes: 1 addition & 28 deletions go/httphelper/http_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ import (
"crypto/tls"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
"sort"
"strings"
)

Expand Down Expand Up @@ -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
}

0 comments on commit 1fa7dcd

Please sign in to comment.