tonyl7126
tonyl7126

Reputation: 1568

go conditional compilation problem

I have two files, production_constants.go and local_constants.go in the same package.

At the top of each I have:

// +build production

package receivers

and

// +build local

package receivers

When I compile with either tag ("go install -tags local", for example) The same constants are used for either tag (ie the compile tags aren't respected). If I remove the build headers, weirdly everything still compiles and the same constants are used. Only when I remove all of the space above the package declaration ("package receivers") do I receive the "_ redeclared in this block".

I'm confused as I think I've done exactly what the documentation has indicated for a conditionally built package. Am I missing something obvious here?

Upvotes: 2

Views: 254

Answers (1)

VonC
VonC

Reputation: 1323065

You can check if this is a compilation issue (as mentioned in this thread) with:

go clean -i receivers
# or
go install -a -tags local

By forcing a full recompilation of every files, the tags should work.

Upvotes: 1

Related Questions