深入了解库 [英] Go dep and forks of libraries

查看:103
本文介绍了深入了解库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解如何使用Golang和forks。情况如下,我正在编写一个库 project ,该项目取决于库 github.com/other/some_dependency ,这不是我的。

I'm trying to understand how to work with Golang and forks. The situation is the following, I'm writing a library project which depends on library github.com/other/some_dependency, which isn't mine.

由于 some_dependency 缺少了我需要的某些方法,因此将其分叉到 github.com/me/some_dependency 。但是,我不能只执行去获取github.com/me/some_dependency ,库会引用它本身,所以它会损坏。

Because some_dependency is missing some methods that I need, I fork it to github.com/me/some_dependency. However, I can't just do go get github.com/me/some_dependency, the library references itself so it breaks.

在此文章他们给出了可能的解决方案:

In this article they give a possible solution:

 go get github.com/other/some_dependency
 cd $GOPATH/src/github.com/other/some_dependency
 git remote add fork git@github.com:me/some_dependency
 git rebase fork/master

现在,这充其量是hacky。从库的代码中无法得知依赖项来自其他存储库。任何执行获得我的图书馆的人都无法使其正常工作。

Now, this is hacky at best. There is no way from the code of the library to know that the dependency is coming from a different repo. Anyone doing go get of my library wouldn't manage to make it work.

dep 有望成为正式的依赖项管理器。我发现了如何修复该版本:

As dep is expected to be the official dependency manager. I've found how to fix the version:

dep ensure -add github.com/foo/bar@v1.0.0

但是我找不到如何设置其他遥控器。有可能做到吗?
例如,在具有npm的Node.js中,它是简单死掉

But I cannot find how to set a different remote. Is is possible to do it? As an example, in Node.js with npm it is dead simple:

npm install git+https://git@github.com/visionmedia/express.git


推荐答案

如果您查看 help ,您将看到以下内容:

If you look at the help you will see this:

<import path>[:alt source URL][@<constraint>]

因此要添加 github.com/foo / bar 从位置 github.com/fork/bar ,您必须像这样添加它:

So to add github.com/foo/bar from location github.com/fork/bar you have to add it like this:

dep ensure -add github.com/foo/bar:github.com/fork/bar

源位置将作为 source 属性添加到 Gopkg.toml 。

The source location will be added as source attribute in the Gopkg.toml.

用于 d依存性规则约束和覆盖

这篇关于深入了解库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆