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

huangapple go评论68阅读模式
英文:

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

huangapple
  • 本文由 发表于 2022年5月15日 20:25:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/72248235.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定