Skip to content

Commit 15d2654

Browse files
mstoykovrs
authored andcommitted
Use syscall instead of x/sys/* (#41)
1 parent 4612dfc commit 15d2654

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

hostid_darwin.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
package xid
44

5-
import "golang.org/x/sys/unix"
5+
import "syscall"
66

77
func readPlatformMachineID() (string, error) {
8-
return unix.Sysctl("kern.uuid")
8+
return syscall.Sysctl("kern.uuid")
99
}

hostid_freebsd.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
package xid
44

5-
import "golang.org/x/sys/unix"
5+
import "syscall"
66

77
func readPlatformMachineID() (string, error) {
8-
return unix.Sysctl("kern.hostuuid")
8+
return syscall.Sysctl("kern.hostuuid")
99
}

hostid_windows.go

+10-11
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,31 @@ package xid
44

55
import (
66
"fmt"
7+
"syscall"
78
"unsafe"
8-
9-
"golang.org/x/sys/windows"
109
)
1110

1211
func readPlatformMachineID() (string, error) {
13-
// source: https://github.com/shirou/gopsutil/blob/master/host/host_windows.go
14-
var h windows.Handle
15-
err := windows.RegOpenKeyEx(windows.HKEY_LOCAL_MACHINE, windows.StringToUTF16Ptr(`SOFTWARE\Microsoft\Cryptography`), 0, windows.KEY_READ|windows.KEY_WOW64_64KEY, &h)
12+
// source: https://github.com/shirou/gopsutil/blob/master/host/host_syscall.go
13+
var h syscall.Handle
14+
err := syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE, syscall.StringToUTF16Ptr(`SOFTWARE\Microsoft\Cryptography`), 0, syscall.KEY_READ|syscall.KEY_WOW64_64KEY, &h)
1615
if err != nil {
1716
return "", err
1817
}
19-
defer windows.RegCloseKey(h)
18+
defer syscall.RegCloseKey(h)
2019

21-
const windowsRegBufLen = 74 // len(`{`) + len(`abcdefgh-1234-456789012-123345456671` * 2) + len(`}`) // 2 == bytes/UTF16
20+
const syscallRegBufLen = 74 // len(`{`) + len(`abcdefgh-1234-456789012-123345456671` * 2) + len(`}`) // 2 == bytes/UTF16
2221
const uuidLen = 36
2322

24-
var regBuf [windowsRegBufLen]uint16
25-
bufLen := uint32(windowsRegBufLen)
23+
var regBuf [syscallRegBufLen]uint16
24+
bufLen := uint32(syscallRegBufLen)
2625
var valType uint32
27-
err = windows.RegQueryValueEx(h, windows.StringToUTF16Ptr(`MachineGuid`), nil, &valType, (*byte)(unsafe.Pointer(&regBuf[0])), &bufLen)
26+
err = syscall.RegQueryValueEx(h, syscall.StringToUTF16Ptr(`MachineGuid`), nil, &valType, (*byte)(unsafe.Pointer(&regBuf[0])), &bufLen)
2827
if err != nil {
2928
return "", err
3029
}
3130

32-
hostID := windows.UTF16ToString(regBuf[:])
31+
hostID := syscall.UTF16ToString(regBuf[:])
3332
hostIDLen := len(hostID)
3433
if hostIDLen != uuidLen {
3534
return "", fmt.Errorf("HostID incorrect: %q\n", hostID)

0 commit comments

Comments
 (0)