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

Time:05-17

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?

CodePudding user response:

You can try reading Raspberry Pi serial number. For example, https://linuxhint.com/find-serial-number-raspberry-pi/#:~:text=Your device serial number is,the content of the file.

Alex

  •  Tags:  
  • go
  • Related