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 }