In the introduction, we saw that a file with a name ending in _test.go
would automatically be run as part of the test phase. Go uses this naming convention for additional compiler features to provide the ability to include code for a specific platform or computer architecture. For example, a file named main_windows.go
will only be included in the compilation if you are building for Microsoft Windows, and the main_darwin.go
file would only be compiled for macOS (darwin is the name of the underlying operating system). Similarly, the computer architecture can be used to conditionally include source code, and so a file named main_arm.go
would only be part of the build for a 32-bit ARM-based processor.
Go also supports the conditional compilation of arbitrary files through the use of build constraints (also known as build tags). These operate at a file level to determine whether a file should be included in the build. To use this functionality, a comment is placed...