I have a little dilemma about the behaviour of the go tool when given
an explicit list of files. I am writing a package for which I want to
provide several single-file programs as examples.
Since there are also subpackages/commands, I'd like to be able to use
go install mypackage/... without it trying to compile together the
samples in mypackage/samples (where sample1.go, sample2.go etc. can be
found). Currently I have no other choice, I think, than either
renaming my samples directory "_samples".
So I tried adding // +build ignore at the top of the samples, but now
I can't do "go build sample1.go" or "go run sample1.go" anymore.
What are your suggestions?
Regards,
Rémy.
I precisely don't want them to be go-installable. They are samples,
not interesting programs. I would like them to be go-runnable (not as
packages but as single files), without them to be go-installable. And
my question is whether this requirement makes any sense to you or
anybody.
Rémy.
Is it OK to ignore build directives for "go run"? Trying to think of a scenario where it'd be problematic. One argument is that anything complex enough to need build directives should really be a package in its own right.
Andrew
go run and go build now assume that if you pass a list of
files you know what you're doing. They ignore the +build lines.