diff options
Diffstat (limited to 'vendor/github.com/rs/xid/hostid_darwin.go')
| -rw-r--r-- | vendor/github.com/rs/xid/hostid_darwin.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/vendor/github.com/rs/xid/hostid_darwin.go b/vendor/github.com/rs/xid/hostid_darwin.go new file mode 100644 index 0000000..1735156 --- /dev/null +++ b/vendor/github.com/rs/xid/hostid_darwin.go @@ -0,0 +1,34 @@ +// +build darwin + +package xid + +import ( + "errors" + "os/exec" + "strings" +) + +func readPlatformMachineID() (string, error) { + ioreg, err := exec.LookPath("ioreg") + if err != nil { + return "", err + } + + cmd := exec.Command(ioreg, "-rd1", "-c", "IOPlatformExpertDevice") + out, err := cmd.CombinedOutput() + if err != nil { + return "", err + } + + for _, line := range strings.Split(string(out), "\n") { + if strings.Contains(line, "IOPlatformUUID") { + parts := strings.SplitAfter(line, `" = "`) + if len(parts) == 2 { + uuid := strings.TrimRight(parts[1], `"`) + return strings.ToLower(uuid), nil + } + } + } + + return "", errors.New("cannot find host id") +} |
