Files
code-utils/machineid_other.go

22 lines
518 B
Go
Raw Normal View History

2026-08-14 07:52:01 +08:00
//go:build !windows
package main
import (
"os"
"strings"
)
// rawMachineID 读取 Linux/macOS 的机器标识;读不到时返回空串由调用方兜底。
func rawMachineID() string {
for _, p := range []string{"/etc/machine-id", "/var/lib/dbus/machine-id"} {
if b, e := os.ReadFile(p); e == nil {
if v := strings.TrimSpace(string(b)); v != "" {
return v
}
}
}
// macOS 没有 machine-id 文件,退回 IOPlatformUUID 太重,直接用主机名兜底(由调用方哈希)。
return ""
}