英文:
How to detect whether my Go code is running on Raspberry Pi and which architecture
问题
我正在使用以下代码来区分我的应用程序运行的平台:
import (
"runtime"
)
func Get() (string, error) {
// 检测我们正在运行的平台。
if runtime.GOOS == "windows" {
// ...
} else if runtime.GOOS == "darwin" {
// ...
} else if runtime.GOOS == "linux" {
// ...
}
// ...
}
现在,我打算检测我的应用程序是否在树莓派上运行,如果是的话,检测它的架构,例如ARM、x86等。
有什么最可靠的方法吗?我可能忽略了哪些标准做法吗?
英文:
I'm using this code to differentiate the platform my application is running on:
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" {
// ...
}
// ...
}
Now, I intend to detect whether my application is running on Raspberry Pi and if so, which architecture, i.e. ARM, x86, ...
What's the most reliable to do so? Any standard practice which I might be missing?
答案1
得分: 1
你可以尝试读取树莓派的序列号。例如,可以参考以下链接:https://linuxhint.com/find-serial-number-raspberry-pi/#:~:text=Your%20device%20serial%20number%20is,the%20content%20of%20the%20file。
Alex
英文:
You can try reading Raspberry Pi serial number. For example, https://linuxhint.com/find-serial-number-raspberry-pi/#:~:text=Your%20device%20serial%20number%20is,the%20content%20of%20the%20file.
Alex
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论