get system architecture in go

To get the system architecture in Go, we can use the runtime and os packages. The runtime package provides information about the Go runtime and the os package provides information about the operating system.

Here is an example code block for getting the architecture of the system:

main.go
package main

import (
	"fmt"
	"runtime"
)

func main() {
	fmt.Printf("System Architecture: %s\n", runtime.GOARCH)
}
117 chars
11 lines

The runtime.GOARCH constant returns a string that represents the architecture of the system. This constant is defined at compile time and is based on the architecture of the machine that the compiler is running on. It can be "amd64", "arm64", "386", etc.

gistlibby LogSnag