Including OS-Specific Files in the Build
Explore the process of implementing a notification sending method for various operating systems.
We'll cover the following...
Overview
Using runtime.GOOS
to verify the current operating system is a practical way to
include OS-specific parameters and data in our application. But it’s not a good approach to include larger pieces of code because doing so might lead to convoluted code and it might not be possible in some cases to redefine the code within the condition block.
In these cases, we can use build constraints, also known as build tags, which are a mechanism that lets us include and exclude files from our build and our tests according to different criteria.
We can use build tags in their most basic form to tag Go source files and include them in our build when we provide the respective tag as a value to the parameter -tags=TAG
when building or testing our code.
Go also allows us to provide tags based on ...