3

我正在尝试通过 go mod 下载项目的所有依赖项;go mod vendor在 CLI上执行时会出现问题。输出如下:

go: finding github.com/hyperledger/fabric-sdk-go v0.0.0-00010101000000-000000000000
go: github.com/hyperledger/fabric-sdk-go@v0.0.0-00010101000000-000000000000: unknown revision 000000000000
go: error loading module requirements

导入库的代码是这样的:

import (    
    "github.com/hyperledger/fabric-sdk-go/pkg/client/ledger"
    "github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt"
    "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
)

krakengosdk 是我正在处理的包的名称:

go mod init krakengosdk

有什么解决办法吗?我一直在寻找任何解决方案,但我没有遇到任何有用的东西。

编辑:我已将 go 版本更新为 1.13;似乎错误必须与“github.com/hyperledger/fabric-sdk-go/test/integration@v0.0.0-20190918153951-5d7ae7a5be8f”有关:

go get -v github.com/hyperledger/fabric-sdk-go/test/integration@latest
go: finding github.com/hyperledger/fabric-sdk-go/test/integration latest
go get: github.com/hyperledger/fabric-sdk-go/test/integration@v0.0.0-20190918153951-5d7ae7a5be8f requires
    github.com/hyperledger/fabric-sdk-go@v0.0.0-00010101000000-000000000000: invalid version: unknown revision 000000000000
4

3 回答 3

4

问题:

  1. 您的确切 go.mod 文件是什么?
  2. 你有什么replace指令github.com/hyperledger/fabric-sdk-go吗?
  3. 如果你现在没有,你曾经做过吗?

v0.0.0-00010101000000-000000000000如果您有replace指令但没有相应的指令,则通常会显示该长版本require,并且该go命令会使用该长版本自动为您添加require指令。

这可能很好,但我想知道你是否做了类似添加 a 的操作replace,但后来删除了replacewhile 将长版本保留v0.0.0-00010101000000-000000000000require. 或类似的东西。

如果您:

  1. 删除您可能拥有replace的任何指令github.com/hyperledger/fabric-sdk-go
  2. require将for更改为github.com/hyperledger/fabric-sdk-go
 require github.com/hyperledger/fabric-sdk-go latest
  1. go list -m all

此外,如果还没有,您应该使用最新版本的 Go 1.13,它修复了一些错误,但通常也有更好的错误消息。

于 2019-09-19T17:31:21.617 回答
2

这发生在我身上是因为使用了替换标志并删除了替换标志。这可以通过使用以下两个命令来纠正。

go mod edit -droprequire=github.com/hyperledger/fabric-sdk-go

上面的命令删除了依赖

go mod tidy

上面的命令重新下载依赖项。

于 2021-05-19T08:12:39.910 回答
1

建议的诊断

我建议在控制台(bash/dash/fish/zsh)中尝试这些命令:


# 1. Create clean project 
$ mkdir /tmp/checkmods && cd /tmp/checkmods  # create clean directory
$ export GO111MODULES=on
$ go version # check that version 1.13
$ go mod init main # name of package does not matter here

# 2. Install packages, check output
$ go get -v github.com/hyperledger/fabric-sdk-go/pkg/client/ledger
$ go get -v github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt
$ go get -v github.com/hyperledger/fabric-sdk-go/pkg/fabsdk

# 3. Create main.go 
$ touch main.go
$ # edit main.go, add imported packages, import something from those packages
$ go mod vendor 
# Do you have problems here? 
# if you encounter problems: 
# - play around  with `go mod tidy`
# - look at `go.mod` and `go.sum`
# - `go mod graph/verify/why` - are your friends

示例main.go

package main

import (
    "fmt"
    "github.com/hyperledger/fabric-sdk-go/pkg/client/ledger"
    "github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt"
    "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
)

func main() {
    var (
        cln  &ledger.Client
        rsm  &resmgmt.Client
        fbs  &fabsdk.FabricSDK
    )
    fmt.Printf("%T %T %T\n", cln, rsm, fbs)
}

分析

如果遇到问题:说明您在哪条线路上遇到了什么样的问题。

如果干净启动一切正常:看看您的项目和干净启动之间有什么不同(go.sum 和 go.mod 的差异)

祝你好运!

于 2019-09-19T18:24:03.973 回答