如何检测我的 Go 代码是否在 Raspberry Pi 上 运行 以及哪种架构

How to detect whether my Go code is running on Raspberry Pi and which architecture

我正在使用此代码来区分我的应用程序在 运行 上的平台:

import (
    "runtime"
)

func Get() (string, error) {
    // Detect platform we are running on.
    if runtime.GOOS == "windows" {
        // ...
    } else if runtime.GOOS == "darwin" {
        // ...
    } else if runtime.GOOS == "linux" {
        // ...
    }

    // ...
}

现在,我打算检测我的应用程序是否在 Raspberry Pi 上 运行,如果是,是哪种架构,即 ARM、x86、...

这样做最靠谱的是什么?我可能会遗漏任何标准做法吗?

您可以尝试读取Raspberry Pi序列号。例如,https://linuxhint.com/find-serial-number-raspberry-pi/#:~:text=Your%20device%20serial%20number%20is,the%20content%20of%20the%20file.

亚历克斯