GoLang 导入 forked 的第三方库

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

GoLang import forked 3rd party

问题

我的情况有点棘手。

我正在使用两个第三方库,我们称它们为AB,而且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
)

huangapple
  • 本文由 发表于 2023年3月28日 13:24:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75862578.html
匿名

发表评论

匿名网友

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

确定