我在创建这篇文章时想出了解决这个问题的方法,但我想我会把我的眼泪留在这里,也许可以帮助遇到同样事情的其他人。最终问题的根源在于教程中的过时说明,没有反映对基础存储库的更改。
我正在从这个页面工作: https ://hyperledger-fabric.readthedocs.io/en/release-1.4/chaincode4ade.html
我的环境: - Ubuntu 18.04 服务器(在 virtualbox 中作为 VM 运行) - 转到版本 1.13.5 - 工作目录:/home/fabric-1/go/src/sacc - $GOPATH:/home/fabric-1/go
同样在 /home/fabric-1/go/src 我已经克隆了织物:
git clone https://github.com/hyperledger/fabric.git
在我的 ~/go/source/sacc 目录中,我根据说明使用以下导入编写了文件:
import (
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/protos/peer"
)
所以当我第一次运行命令时
go get -u github.com/hyperledger/fabric/core/chaincode/shim
我收到一条错误消息,指出它找不到包“shim”。我在 github.com 目录上执行了“查找”命令,发现它在那里,但是在一个奇怪的地方,我尝试将 shim 目录移动到某个友好的地方,这导致当你执行类似的操作时通常会出现兔子洞狂热那 ...
在花了一天的时间,尝试从其他地方安装 shim 代码之后,我终于意识到(呃!)更改 shim 的导入语句:
import (
"fmt"
"github.com/hyperledger/fabric/vendor/github.com/hyperledger/fabric-chaincode-go/shim"
"github.com/hyperledger/fabric/protos/peer"
)
在此之后,“go get”找到了,但“go build”失败了——找不到“peer”(叹气)
午休后(并抵制了喝伏特加酒的诱惑),我认为他们在编写教程后重新安排了一些事情。我仔细查看了路径,发现其他 github.com 目录下还有 github.com 目录。于是回到github(终于不怕了),找到对应子目录的repositories:
https://github.som/hyperledger/fabric/fabric-chaincode-go
https://github.som/hyperledger/fabric/fabric-protos-go
我将这些克隆到我的环境中:
cd $GOPATH/src/github.com/hyperledger
git clone https://github.som/hyperledger/fabric/fabric-chaincode-go
git clone https://github.som/hyperledger/fabric/fabric-protos-go
然后我再次返回并更改了 sacc.go 代码中的导入语句:
import (
"fmt"
"github.com/hyperledger/fabric-chaincode-go/shim"
"github.com/hyperledger/fabric-protos-go/peer"
)
嘿!是的!'go get' 和 'go build' 命令工作得很好,编译成功,现在开始下一个问题(好吧,好吧,实际上是明天 - 天很黑很冷,我想我会去做伏特加我之前没喝过)。