如何使用本地 git checkout 来跟踪更改的 Go 依赖项

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

How to use local git checkout for a go dependency for change tracking

问题

我被卡在了以下的挑战中:

在开发代码的同时,我还想并行开发一个依赖项(micromdm/scep),并使用git跟踪更改。

我的代码导入库的方式如下:

import(
    ...
    sscepclient "github.com/micromdm/scep/v2/client"
    "github.com/micromdm/scep/v2/cryptoutil/x509util"
    "github.com/micromdm/scep/v2/scep"
)

为了指向本地检出的模块版本,我在go.mod中替换了模块:

require (
...
github.com/micromdm/scep/v2 v2.0.0
)
replace github.com/micromdm/scep/v2 => /home/pi/go/scep

我在scep模块的存储库上进行了git克隆,并且可以在replace指令指定的目录中找到文件。

但是当我尝试运行我的代码时,我遇到了一个错误:

../../scep/server/csrsigner.go:8:2: no required module provides package github.com/micromdm/scep/v2/scep; to add it:
        go get github.com/micromdm/scep/v2/scep

如果我按照要求执行go get依赖项,我会收到以下错误消息:

go get: module github.com/micromdm/scep/v2@upgrade found (v2.0.0, replaced by /home/pi/go/scep), but does not contain package github.com/micromdm/scep/v2/scep

我还尝试在依赖模块的go.mod中添加replace语句,因为该模块还有几个require语句指向scep模块,但没有成功。

据我所了解,GO无法找到这些模块(显然),但老实说,依赖项的处理真的让我困惑。根据我在互联网上找到的信息,我了解到使用replace指令应该可以实现对本地检出存储库的开发。如果有人能给我一些指导,我将不胜感激。谢谢!

英文:

I'm stuck with the following challenge:

While developing code, I would also like to develop a dependency (micromdm/scep) in parallel and track changes using git.

My code imports the library like this:

import(
    ...
    sscepclient "github.com/micromdm/scep/v2/client"
    "github.com/micromdm/scep/v2/cryptoutil/x509util"
    "github.com/micromdm/scep/v2/scep"
)

To point go to a locally chekced out version of the module, I replaced the module in my go.mod:

require (
...
github.com/micromdm/scep/v2 v2.0.0
)
replace github.com/micromdm/scep/v2 => /home/pi/go/scep

I did do a git clone on the repository of the scep module and can find the files in the directory specified with the replace directive.

But when I try to run my code, I get an error

../../scep/server/csrsigner.go:8:2: no required module provides package github.com/micromdm/scep/v2/scep; to add it:
        go get github.com/micromdm/scep/v2/scep

If I do go get the dependency as requested, I get the error message

go get: module github.com/micromdm/scep/v2@upgrade found (v2.0.0, replaced by /home/pi/go/scep), but does not contain package github.com/micromdm/scep/v2/scep

I also tried to add the replace statement in the dependency module's go.mod itself since the module also has several require statements that direct to the scep module, but without success.

From what I understand, GO is not able to find the modules (obviously) but to be honest, the handling of dependencies really confuses me. From what I found on the internet I understood that such a development of a locally checked-out repository should be possible by using the replace directive. I would be glad if someone could shed some light on this. Thank you!

答案1

得分: 0

  1. 检查是否定义了模块版本(v2)

    module github.com/micromdm/scep/v2 @ /home/pi/go/scep/go.mod

  2. 将模块的路径更改为相对路径,在这种情况下,它可以工作

更新 1: 我看到你已经这样做了,但这是我脑海中唯一的选择。

更新 2: 找到了一个小的解决方案。

英文:
  1. Check if you have defined module version (v2)

    module github.com/micromdm/scep/v2 @ /home/pi/go/scep/go.mod

  2. change the path to the module to be relative, in this case, it works.

update 1: I see you did, but that only option I got in my mind.

update 2: found a small solution.

huangapple
  • 本文由 发表于 2021年8月13日 14:50:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/68767954.html
匿名

发表评论

匿名网友

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

确定