下载并准备Go包的依赖项,以便在另一台隔离的机器上使用。

huangapple go评论81阅读模式
英文:

Download and prepare go package's dependencies to be used on another, isolated machine

问题

我有两台机器:AliceBobAlice 不连接网络,而 Bob 连接网络。

我想在 Alice 上构建和运行一个 Go 程序,但它需要多个依赖项。有没有一种方便的方法可以从 Bob 准备所有这些依赖项,这样我只需要将一个目录从 Bob 复制到 Alice,然后在 Alice 上运行 go build

英文:

I've got two machines: Alice and Bob. Alice is not connected to the network, Bob is.

I'd like to build and run a go program on Alice, but it requires multiple dependencies. Is there a convenient way to prepare all those dependencies from Bob so I just have to copy one directory from Bob to Alice and run go build (on Alice)?

答案1

得分: 2

所有编译的源代码都在$GOPATH中。将其复制到Alice将为您提供重建软件包所需的一切。由于您的源代码也应该在$GOPATH中,所以不需要复制其他内容。

如果您使用的是go1.6+或带有GO15VENDOREXPERIMENT=1的go1.5,您可以将所有依赖项放入项目的vendor/子目录中,以便将它们一起打包。

在go中进行交叉编译也非常简单(除非您需要cgo),只需设置GOOSGOARCH环境变量即可。

Go构建参考文档:https://golang.org/pkg/go/build/

http://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5

英文:

All the source for compilation is in $GOPATH. Copying that to Alice will give you everything you need to rebuild the package. Since your source should be in $GOPATH as well, there shouldn't be anything else to copy.

If you're using go1.6+, or go1.5 with GO15VENDOREXPERIMENT=1, you can put all the dependencies into a vendor/ subdirectory of your project, to package them together.

Cross-compilation is also very easy in go (unless you require cgo), by setting the GOOS and GOARCH environment variables.

Go build reference: https://golang.org/pkg/go/build/

http://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5

huangapple
  • 本文由 发表于 2016年3月15日 00:00:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/35992322.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定