英文:
package.json equivalent in Golang
问题
我正在从Node.js转到Go,习惯了添加所有的模块,然后其他人只需在克隆我的包后运行npm install
。
在Go中,相当于这个的是什么?我有几个导入的包,不希望其他人在使用我的包时需要手动安装它们。
我也不确定如果我创建一个只有package main
的简单Go应用程序,是否允许其他人使用go get
。我对Go的仓库共享方式还不太了解,就像Node.js那样。
英文:
I am coming over to Go from Node.js and I am used to adding all my modules and then people just have to go npm install
when cloning my package.
What is the equivalent of this with Go? I have a few imports and don't want people to have to manually install it if they use my package.
I also not sure if I create a simple Go application with just a package main
if that allows people to just go get
. I have really picked up on the Go way of repo sharing like Node.js
答案1
得分: 5
这个问题的中文翻译如下:
你不需要做任何事情。人们不需要手动安装你导入的包。当有人执行以下命令时:
go get github.com/FrickeFresh/awesome
你在awesome包中导入的所有依赖项将会根据需要自动下载。
go get默认跳过测试文件,但用户可以通过包含-t选项来下载这些文件:
go get -t github.com/FrickeFresh/awesome
但这不是你需要担心的事情。
如果你想深入研究特定版本的依赖项的供应商,有许多文章和工具可供使用。官方工具是dep:
英文:
> What is the equivalent of this with Go? I have a few imports and don't want people to have to manually install it if they use my package.
You don't have to do anything. People will not have to manually install the packages you import. When someone does
go get github.com/FrickeFresh/awesome
all of the dependencies you import in your awesome package will be downloaded automatically as needed.
Go get skips testing files by default, but a user can download those too by including -t:
go get -t github.com/FrickeFresh/awesome
But that's not something you need to worry about.
If you want to delve into vendoring specific versions of dependencies, there are a number of articles/tools available. The official tool is dep:
答案2
得分: 1
基本上,你应该看一下 vendoring(供应商管理)。存在一些工具可以帮助你进行版本管理。个人而言,我使用的是 vendetta,它只是一个小工具,将引用的包作为 git 子模块获取到 vendor 文件夹中。因此,如果有人检出我的仓库,他们只需执行 git submodule update --init --recursive
。包的版本可以在相应的子模块中指定为 git 提交 ID。
还有一些工具可以在文件中维护依赖项,请参考这里。
英文:
Basically you should take a look at vendoring. There exist tools that help you with versioning. Personally, I use vendetta which is just a little tool that "go gets" the referenced packages as git submodules into the vendor folder. So if anyone checks out my repo they simply do git submodule update --init --recursive
. The package version can be specified as a git commit id in the respective submodule.
There also exist tools where you maintain the deps in a file, check out here.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论