Build Constraints
Go programs can run on different OSes and different CPU architectures. When you build a Go program, the compilation of your program is done for your current machine's OS and architecture. By using the build constraints, you can set conditions on which a file will be considered for compilation. If you have a function that needs to be overridden for different OSes, you can use build constraints to have multiple definitions of the same function.
You can see lots of examples of this happening in the Go standard library.
The following links are implementations of the same function in darwin and on Linux from the os
package in the standard library:
If you happen to come across a similar requirement, the Go language provides build constraints that can be used to define build conditions.
Build Tags
There are two ways to use build constraints. The first method is to define build tags...