Compare commits
No commits in common. "master" and "v0.0.2" have entirely different histories.
|
@ -1,6 +1,3 @@
|
||||||
Get() the full hostname for the OS.
|
Get() the full hostname for the OS.
|
||||||
|
|
||||||
* only cares about the hostname in DNS
|
* only cares about the hostname in DNS
|
||||||
* I wrote this before or not being aware of os.Hostname()
|
|
||||||
|
|
||||||
probably this package should go away
|
|
||||||
|
|
8
get.go
8
get.go
|
@ -1,17 +1,9 @@
|
||||||
package hostname
|
package hostname
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
// returns the hostname
|
// returns the hostname
|
||||||
// hostname is always set to the best effort
|
// hostname is always set to the best effort
|
||||||
// error is set if hostname isn't real
|
// error is set if hostname isn't real
|
||||||
func Get() (string, error) {
|
func Get() (string, error) {
|
||||||
hostname, err := osGetHostname()
|
hostname, err := osGetHostname()
|
||||||
if hostname == "" {
|
|
||||||
if err == nil {
|
|
||||||
err = fmt.Errorf("your machines' hostname is not set")
|
|
||||||
}
|
|
||||||
hostname = "unconfigured.hostname"
|
|
||||||
}
|
|
||||||
return hostname, err
|
return hostname, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,12 @@ import (
|
||||||
// scutil --set HostName my-mac.example.com
|
// scutil --set HostName my-mac.example.com
|
||||||
|
|
||||||
func osGetHostname() (string, error) {
|
func osGetHostname() (string, error) {
|
||||||
return scutil([]string{"--get", "HostName"})
|
return scutil([]string{"-get", "HostName"})
|
||||||
}
|
}
|
||||||
|
|
||||||
// getDomainName executes the 'domainname' command and returns its output.
|
// getDomainName executes the 'domainname' command and returns its output.
|
||||||
func scutil(args []string) (string, error) {
|
func scutil(args []string) (string, error) {
|
||||||
cmd := exec.Command("scutil", args...)
|
cmd := exec.Command("scutil", args)
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue