| 22 | } |
| 23 | |
| 24 | func getHostname() string { |
| 25 | h, err := os.Hostname() |
| 26 | if err != nil { |
| 27 | // Something must be very wrong if this fails. |
| 28 | // We'll just return localhost and hope for the best. |
| 29 | return "localhost" |
| 30 | } |
| 31 | |
| 32 | // On some platforms, the hostname can be an FQDN. We only want the hostname. |
| 33 | if idx := strings.Index(h, "."); idx != -1 { |
| 34 | h = h[:idx] |
| 35 | } |
| 36 | |
| 37 | // For the sake of consistency, we also want to lowercase the hostname. |
| 38 | // Per RFC 4343, DNS lookups must be case-insensitive. |
| 39 | return strings.ToLower(h) |
| 40 | } |