As seen here, go build accepts a "tags" flag that will include files that are "tagged," i.e.
// +build foo
package main
....
will be excluded from
go build
but included in
go build -tags=foo
Is there a way to include multiple tags? I.e.
go build -tags=foo && bar
Developer and author at DigitalOcean. In Go, a build tag, or a build constraint, is an identifier added to a piece of code that determines when the file should be included in a package during the build process.
So if you want to run the test only for the build tags func_test then you need to provide a different tag for the other tests. Here is an example: I have following 2 test files in my test directory.
// ReleaseTags defaults to the list of Go releases the current release is compatible with. // BuildTags is not set for the Default build Context. // In addition to the BuildTags, ToolTags, and ReleaseTags, build constraints // consider the values of GOARCH and GOOS as satisfied tags.
When running the go build command, we can use the -tags flag to conditionally include code in the compiled source by adding the tag itself as an argument. Let’s do this for the pro tag: Now we only get the extra features when we build the application using the pro build tag.
Multiple tags can be included in a space separated list:
go build -tags="foo bar"
You should prefer including multiple tags in a comma separated list:
go build -tags=a,b
From Go 1.13 release notes:
The go build flag -tags now takes a comma-separated list of build tags, to allow for multiple tags in GOFLAGS. The space-separated form is deprecated but still recognized and will be maintained.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With