summaryrefslogtreecommitdiff
path: root/get.go
blob: ece18edd3cdd944711ac16754d294ebc5c546cde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package hostname

import "fmt"

// returns the hostname
// hostname is always set to the best effort
// error is set if hostname isn't real
func Get() (string, error) {
	hostname, err := osGetHostname()
	if hostname == "" {
		if err == nil {
			err = fmt.Errorf("your machines' hostname is not set")
		}
		hostname = "unconfigured.hostname"
	}
	return hostname, err
}