Golang requirements.txt equivalent

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

Golang requirements.txt equivalent

问题

作为一个来自Python/Django世界的开发者,我理解你想要类似于Python中的requirements.txt的东西来管理Go/Revel项目的依赖。在Go语言中,你可以使用Go Modules来管理项目的依赖关系。

首先,你需要在项目的根目录下初始化Go Modules。在终端中,进入项目目录并运行以下命令:

go mod init <module_name>

这将创建一个go.mod文件,用于记录项目的依赖关系。

然后,你可以使用go get命令来安装项目的直接依赖。例如:

go get <dependency_name>

这将下载并安装指定的依赖包,并将其添加到go.mod文件中。

如果你的依赖还有其他依赖,Go Modules会自动解析并下载它们。你不需要手动处理这些依赖关系。

最后,你可以使用以下命令来下载并安装所有项目的依赖:

go mod download

这将根据go.mod文件中记录的依赖关系下载并安装所有的依赖包。

希望这可以帮助到你!如果你还有其他问题,请随时提问。

英文:

Coming from a python/django world, it'd be great to have something like a requirements.txt equivalent for go/revel. How can I do this? I know I can just write a requirements.txt file and then do something like

cat requirements | xargs go get

But what if my requirements ALSO have requirements? The above command would attempt to "go get" them, and then they'd fail to build, since I don't have those requirements installed.

Is there something I'm missing?

答案1

得分: 17

go get命令正是你所需要的:它会查找所有的依赖项,并下载和安装缺失的依赖项。重点是“all”:go get确实会遍历你的依赖图。

请查看文档:

https://golang.org/cmd/go/#hdr-Add_dependencies_to_current_module_and_install_them

Go的文档非常清晰、简洁和易于理解。我建议在做出基于对其他工具或工具链的经验的假设之前,先查看文档。

他们还提供了一些有用的博客文章,https://blog.golang.org/using-go-modules

英文:

The command go get does exactly what you need: It finds all dependencies and downloads and installs the missing ones. Focus on "all": go get really traverses your dependency graph.

Have a look at the documentation:

https://golang.org/cmd/go/#hdr-Add_dependencies_to_current_module_and_install_them

The Go documentation is really clean, short and well written. I would recommend always to have a look at the documentation first before making assumptions which are based on experience with other tools or tool-chains.

They also provide useful blog posts, https://blog.golang.org/using-go-modules

答案2

得分: 3

我刚刚发现 Kubernetes 的开发团队实际上为自己创建了一个概览页面,链接在这里

总结一下:目前稳定的工具是 Glide,而新的有趣工具被称为 dep

英文:

I just found that the kubernetes guys actually have created an overview page for themselves here.

Summary is this: Currently stable is Glide and the cool new toy is called dep

huangapple
  • 本文由 发表于 2013年8月28日 14:54:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/18481204.html
匿名

发表评论

匿名网友

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

确定