Developing for Multiple Platforms with Conditional Compiling
Platform based conditional compiling comes in two forms in Go, one is with file suffixes and the other is with build tags.
- After “
// +build”, a single platform or a list can follow
- Platform can be reverted by preceding it by
- List of space separated platforms are ORed together
Caveats for build tags: * The
// +build constraint must be placed at the top of the file, even before package clause. * It must be followed by one blank line to separate from package comments.
List of valid platforms for both build tags and file suffixesandroiddarwindragonflyfreebsdlinuxnetbsdopenbsdplan9solariswindows
$GOOS list in https://golang.org/doc/install/source#environment for the most up-to-date platform list.