How to Determine GOOS and GOARCH Values Used to Build an Executable
As the title suggests, it's possible to ascertain the values of GOOS and GOARCH that were used to compile a specific Go executable.
The key lies in the runtime package, which houses constants that hold this information. These constants are set during compilation and do not affect runtime execution.
Specifically, look for these constants:
To illustrate this, consider a simple Go application:
<code class="go">package main import "fmt" func main() { fmt.Println(runtime.GOOS) fmt.Println(runtime.GOARCH) }</code>
If we execute this code with GOOS=windows and GOARCH=amd64, the output will be:
windows amd64
Alternatively, if we build an executable from this code, it will retain these GOOS and GOARCH values, even if the environment variables are modified later.
So, to determine the GOOS and GOARCH values used to build an executable, simply:
The above is the detailed content of How to Find the GOOS and GOARCH Values Used to Build a Go Executable?. For more information, please follow other related articles on the PHP Chinese website!