shaouai
shaouai

Reputation: 55

What does OMIT mean in a Go build constraint?

I found // +build OMIT in this page https://blog.golang.org/context/server/server.go

I know what a build constraint is.

OMIT isn't

  1. a GOOS or GOARCH value
  2. a compiler name
  3. cgo
  4. a term for each Go major release as go1.12
  5. any additional tags given by the -tags flag

Does it literally mean "omit something here" as // +build ignore keeps a file from being considered for the build ?

Upvotes: 0

Views: 804

Answers (1)

user13631587
user13631587

Reputation:

The source file is ignored when the the build tag OMIT is not specified. It works the same way as ignore. The OMIT and ignore tags have no special meaning to the build tools.

The file is included in the blog post using the present package .code command. The .code command ignores source file lines ending with OMIT.

In summary, two things are going on. The build constraint is used to ignore the file. The tag OMIT is used instead of the more common ignore so that the build constraint does not appear in the blog post.

The program is run using go run server.go. The go run command ignores build constraints.

Upvotes: 2

Related Questions