你如何使-tags netgo成为默认值? [英] How do you make -tags netgo the default for go?
问题描述
为了编译我的golang包以便产生一个静态链接的可执行文件,我必须说:
go install -tags netgo
另外我现在意识到在没有gcc的系统上,我必须:
go get -tags netgo github.com/mypackage / ...
go test -tags netgo。/ ...
如果你一直在输入这个数字,它就不那么好了。我设置了别名,这样我可以输入较少,但有没有一种更好或适当的方式来设置 - 将netgo标记为某种默认值?理想情况下,作为我的软件包本身的一部分,所以尝试使用我的软件包的陌生人不会错过-tags netgo。
编辑:我也希望有可能说: go install -tags netgo -ldflags'-linkmode external -extldflags -static -w'
即,链接到可以静态编译的C代码。所以它在没有GCC的机器上工作对我来说不那么重要,而不是产生静态链接的可执行文件。我只是想知道是否有办法做到后一种情况,而无需一直标记netgo。
您可以完全禁用cgo通过设置 CGO_ENABLED = 0
来防止net包连接到主机解析器。 To compile my golang package so that it produces a statically linked executable, I must say:
go install -tags netgo
Additionally I now realise that on a system without gcc, I must:
go get -tags netgo github.com/mypackage/...
go test -tags netgo ./...
If you're typing this all the time it's no so nice. I have aliases set up so I can type less, but is there a "nicer" or "proper" way to set -tags netgo as some kind of default? Ideally as part of my package itself, so a stranger trying to work with my package doesn't miss the -tags netgo.
Edit: I also want the possibility to say:
go install -tags netgo -ldflags '-linkmode external -extldflags -static -w'
Ie. link to C code that can be statically compiled. So it working on a machine without GCC is less important to me than it producing a statically linked executable. I just wonder if there's a way to do the latter without saying -tags netgo all the time.
You can disable cgo altogether by setting CGO_ENABLED=0
which will prevent the net package from linking to the host resolver.
这篇关于你如何使-tags netgo成为默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!