如何获取程序的所有依赖文件

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

How to get all dependency files for a program

问题

我在Go语言中编写了一个程序,在完成代码后,如果我想在其他计算机或虚拟机上运行这段代码,那么它无法获取所有的依赖包文件。我该如何获取所有的依赖文件?

英文:

I make a program in Go and after completing the code, if I want to run this code on other pc or VM, then it does not get all the dependency package files. How can I get all dependency files?

答案1

得分: 272

你可以在项目目录下运行go get -d ./...命令来下载所有可获取的Go依赖项。
或者将你的GOPATH中的所有src子目录复制到目标机器上。
...是一个特殊的模式,表示递归向下。

英文:

You can run go get -d ./... from a directory of your project to download all go-gettable dependencies.
Or copy all src subdirectory from your GOPATH to the destination machine.
... is a special pattern, tells to go down recursively.

答案2

得分: 60

尝试使用以下命令进行翻译:

go list -f '{{ join .Imports "\n" }}'

或者

go list -f '{{ join .Deps "\n" }}'

第二个命令将列出所有的子依赖项,而第一个命令只列出直接导入的包。

英文:

Try

go list -f '{{ join .Imports "\n" }}'

or

go list -f '{{ join .Deps "\n" }}'

The second will list all subdependencies, the first only the directly imported packages.

答案3

得分: 50

以下命令适用于我,它会下载所有的依赖项。

go get -u -v -f all
英文:

Below command works for me it downloads all the dependencies.

go get -u -v -f all

答案4

得分: 12

这是要翻译的内容:

"它是 go mod download。要获取更多信息,请查看 go help mod。"

英文:

It's go mod download. For more info check go help mod

答案5

得分: 9

你可以在完成程序的本地计算机上使用godep save命令。godep save会为你收集所有的依赖文件。当你切换到其他计算机时,只需将带有代码的Godep文件夹复制过去,它将解决你的问题。

英文:

You can use godep save in your local pc where you complete your program. godep save collect all the dependency files for you. When you move to other pc, just copy the Godep folder with your code and it will solve your problems.

答案6

得分: 8

如果你正在使用模块模式,你可以尝试使用go mod tidy命令,具体描述可以参考这里

英文:

If you are using module mode, you can try go mod tidy, as described here.

答案7

得分: 0

最好的方法是获取列表并迭代安装软件包,这样效果非常好:

while read l; do go get -v "$l"; done < <(go list -f '{{ join .Imports "\n" }}')
英文:

Best way ever is get the list and iterate installing the packages, this works so fine:

while read l; do go get -v &quot;$l&quot;; done &lt; &lt;(go list -f &#39;{{ join .Imports &quot;\n&quot; }}&#39;)

huangapple
  • 本文由 发表于 2015年9月24日 17:45:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/32758235.html
匿名

发表评论

匿名网友

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

确定