Build constraints in Go
A //go:build line decides whether the file is compiled at all.
//go:build linux || darwin
package platform
// Name reports the family this file was built for.
func Name() string { return "unix" }
// TempPattern is the pattern used for scratch files here.
const TempPattern = "/tmp/typestar-*"
How it works
- The constraint must appear before the package clause.
- Filename suffixes like _linux.go do the same thing implicitly.
- It is how one package carries per-platform implementations.
Keywords and builtins used here
constfuncreturnstring
The run, in numbers
- Lines
- 9
- Characters to type
- 232
- Tokens
- 18
- Three-star pace
- 105 tpm
At the three-star pace of 105 tokens a minute, this run takes about 10 seconds.
Step 3 of 5 in Packages & build, step 23 of 26 in Standard library & project layout.