typestar

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

  1. The constraint must appear before the package clause.
  2. Filename suffixes like _linux.go do the same thing implicitly.
  3. It is how one package carries per-platform implementations.

Keywords and builtins used here

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.

Type this snippet

Step 3 of 5 in Packages & build, step 23 of 26 in Standard library & project layout.

← Previous Next →