英文:
GoLang import forked 3rd party
问题
我的情况有点棘手。
我正在使用两个第三方库,我们称它们为A和B,而且A正在使用B。
现在,我分叉了B,所以我有了Forked_B。
我需要A使用Forked_B。
有没有办法做到这一点?欺骗系统?(除了也分叉A)。
谢谢
我想过也分叉A并使用Forked_B。
英文:
My case is bit tricky.
I'm using two 3rd parties, let's call them A and B, also A is using B.
Now, I forked B so I've Forked_B.
And I need that A will use Forked_B.
Is there a way to do it? to trick the system? (except to fork also A).
Thanks
I though to fork A also and use the Forked_B..
答案1
得分: 1
看起来你可能想使用Go的replace
指令,请参考这里的文档:https://go.dev/ref/mod#go-mod-file-replace。不过,通常情况下,replace
指令并不是长期解决方案。
如果你正在使用A,并且A依赖于B,而你有B的一个分支,那么你也应该分叉A并更新其对B的依赖,以使用你的B分支。然后在引用A的代码中,你可以引用你的A分支。
以下是如何在go.mod
中使用replace
指令的示例:
module github.com/company/mypackage
go 1.20
replace github.com/vendor/b => ../path/to/your/fork/of/b
require (
github.com/vendor/a v1.0.0
github.com/vendor/b v1.0.0
)
英文:
It sounds like you might want to be using the Go replace
directive, see the documentation for it here: https://go.dev/ref/mod#go-mod-file-replace. That said, usually the replace
directive is not the long term solution.
If you are using A, and A depends on B, and you have a fork of B, you should also fork A and update its dependency to B to use your fork. Then in the code you're referencing A you can instead reference your fork of A.
Here's an example of how to use the replace
directive in a go.mod
module github.com/company/mypackage
go 1.20
replace github.com/vendor/b => ../path/to/your/fork/of/b
require (
github.com/vendor/a v1.0.0
github.com/vendor/b v1.0.0
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论