将依赖项替换为私有分支的方法是通过Go mod进行的。

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

Go mod replace dependency with private fork

问题

我已经将依赖项添加到了go.mod文件中:

require (
	github.com/labstack/echo/v4 v4.3.1
)

replace (
	github.com/labstack/echo/v4 => example.com/echo/v4.git v4.3.1
)

但是我遇到了一个错误,错误信息是replace example.com/echo.git: version "v4.3.1" invalid: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v4。在仓库中存在所需版本的标签。

当我尝试使用版本号v1.2.1-0.20210520145606-2defe74d39f0时,我得到了类似以下的错误:

replace (
	github.com/labstack/echo/v4 => example.com/echo/v4.git v1.2.1-0.20210520145606-2defe74d39f0
)

我遇到了与私有Git服务器相关的errno=Connection refused错误。

请问我做错了什么,我该如何使用我的私有分支替换依赖项?

英文:

I added the dependency to go.mod:

require (
	github.com/labstack/echo/v4 v4.3.1
)

replace (
	github.com/labstack/echo/v4 => example.com/echo/v4.git v4.3.1
)

And getting error like replace example.com/echo.git: version "v4.3.1" invalid: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v4. Tag with the required version exists in the repo.

While I'm tried to play with the version I got something like v1.2.1-0.20210520145606-2defe74d39f0, but when I set my replace section like:

replace (
	github.com/labstack/echo/v4 => example.com/echo/v4.git v1.2.1-0.20210520145606-2defe74d39f0
)

I'm getting the error errno=Connection refused related to the private git server.

Could you please advise what I'm doing wrong and how I can replace dependency with my private fork?

答案1

得分: 2

  • 确保你的仓库路径是准确的。v4.git表示该仓库名为v4;如果是这样的话,那就没问题,但如果不是,请将其替换为正确的仓库名,并在后面保留v4.x.x标签。

  • 如果该分支是私有的,sum.golang.org可能无法访问。请确保将GOPRIVATE设置为你的私有分支,这样Go就不会尝试获取校验和。

    go env -w GOPRIVATE=example.com
    
英文:
  • Make sure your repo path is accurate. v4.git means the repo is called v4; if that’s true that’s ok, but if not replace it with the correct name of the repo and keep the v4.x.x tag after it.

  • If the fork is private it’s probably not accessible by sum.golang.org. Make sure GOPRIVATE is set to your private fork so Go does not try to get the checksum.

    go env -w GOPRIVATE=example.com
    

答案2

得分: 2

如果替代的仓库托管在 example.com/echo 的 Git 仓库中,那么替代路径应该是 example.com/echo.git/v4

replace (
    github.com/labstack/echo/v4 v4.3.1 => example.com/echo.git/v4 v4.3.1
)

如果 example.com 服务器提供 go-import 元数据,那么你可能可以完全省略 .git 后缀:

replace (
    github.com/labstack/echo/v4 v4.3.1 => example.com/echo/v4 v4.3.1
)
英文:

If the replacement repo is hosted in a Git repository at example.com/echo, then the path to the replacement should probably be example.com/echo.git/v4:

replace (
    github.com/labstack/echo/v4 v4.3.1 => example.com/echo.git/v4 v4.3.1
)

If the example.com server serves go-import metadata, then you may be able to omit the .git suffix entirely:

replace (
    github.com/labstack/echo/v4 v4.3.1 => example.com/echo/v4 v4.3.1
)

huangapple
  • 本文由 发表于 2021年5月24日 22:55:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/67674280.html
匿名

发表评论

匿名网友

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

确定