Junior — Middle
Kuidas tagab Go võimaluse arendada platvormidevahelisi rakendusi?
sobes.tech AI
Vastus AI-lt
Go provides cross-platform development thanks to built-in support for compiling for different operating systems and processor architectures. The main mechanisms:
-
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: Go's standard library is cross-platform, simplifying portability.
Example of compiling for Windows from Linux:
GOOS=windows GOARCH=amd64 go build -o myapp.exe main.go
This way, a developer can create applications for different platforms using the same source code and Go tools.