Junior — Middle
How does Go enable the development of cross-platform applications?
sobes.tech AI
Answer from AI
Go provides cross-platform development through built-in support for compiling to different operating systems and processor architectures. The main mechanisms are:
-
Environment variables GOOS and GOARCH: allow specifying the target OS (e.g., windows, linux, darwin) and architecture (amd64, arm, 386, etc.) before compilation.
-
Single compiler: compiles source code into a native executable for the chosen platform.
-
No external dependencies: the standard library of Go is cross-platform, which simplifies portability.
Example of compiling for Windows from Linux:
GOOS=windows GOARCH=amd64 go build -o myapp.exe main.go
Thus, a developer can create applications for different platforms using the same source code and Go tools.