下载Go包

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

Downloading Go Packages

问题

我从Github克隆了一个项目,在开始工作之前,我必须安装go.mod文件中列出的所有依赖项。

我可以使用go get命令一个一个地安装它们,但是否有其他替代方法呢?
类似于npm i,它可以一次性安装所需的所有依赖项。

或者我可能理解错了。

英文:

I cloned a project from Github and before starting to work I have to install all the dependencies listed in the go.mod file.

I can do it one my one using the go get command, but is there any other alternative to this.
Something like npm i and it installs the required dependencies all at once.

Or maybe I am getting something wrong here.

答案1

得分: 4

go命令会根据需要自动下载依赖项。

在包含 go.mod 文件的目录中执行命令 go mod download,以确保将所有模块依赖项下载到本地模块缓存中。

有关更多详细信息,请参阅 go mod download 文档。

英文:

The go command automatically downloads dependencies as needed.

Execute the command go mod download in the directory containing go.mod to ensure that all of the module dependencies are downloaded to the local module cache.

See the go mod download documentation for more details.

答案2

得分: 2

通常情况下,不需要手动下载在go.mod文件中列出的包。go命令可以自动下载项目的直接和传递依赖项到模块缓存中,然后在构建项目时使用这些已下载的包。

npm的工作方式不同,它将项目的所有直接和传递依赖项下载到项目本地的node_modules目录中。

如果你想在Go中实现类似npm的包管理,最接近的方法是使用Go的Vendoring功能。

go mod vendor 命令会在主模块的根目录下创建一个名为vendor的目录,其中包含支持主模块中包的构建和测试所需的所有包。

有关Vendoring的更详细信息,请参阅官方的Go文档

英文:

Usually there is no need to download packages manually that are listed in go.mod file. go command can automatically download all direct and transitive dependencies of the project in the module cache and then use those downloaded packages while building the project.

npm works differently since it downloads all direct and transitive dependencies of a project into a node_modules directory local to the project.

If you want npm like package management in Go, the closest you can get is with the Vendoring feature of Go.

go mod vendor command creates a directory named vendor in the root of main module containing all the packages that are necessary to support the builds and tests of the packages in the main module.

More detailed information about Vendoring is available in official Go docs.

答案3

得分: 0

你可以尝试使用以下命令:

go list
英文:

You can try it the command

go list

huangapple
  • 本文由 发表于 2021年7月3日 15:08:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/68233977.html
匿名

发表评论

匿名网友

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

确定