diff --git a/README.md b/README.md index 4a341e6..4d71e89 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ Get() the full hostname for the OS. * only cares about the hostname in DNS +* I wrote this before or not being aware of os.Hostname() + +probably this package should go away diff --git a/get.go b/get.go index 0395e98..ece18ed 100644 --- a/get.go +++ b/get.go @@ -1,9 +1,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 } diff --git a/get_darwin.go b/get_darwin.go index 11157c5..d98ce8a 100644 --- a/get_darwin.go +++ b/get_darwin.go @@ -12,7 +12,7 @@ import ( // scutil --set HostName my-mac.example.com func osGetHostname() (string, error) { - return scutil([]string{"-get", "HostName"}) + return scutil([]string{"--get", "HostName"}) } // getDomainName executes the 'domainname' command and returns its output.