如何解决在Docker容器中找不到软件包ipfs,peer和shim软件包
我正在使用第一个网络设置和fabric:v1.4
package main
import (
"bytes"
"encoding/json"
"fmt"
"strconv"
"github.com/hyperledger/fabric/core/chaincode/shim"
peer "github.com/hyperledger/fabric/protos/peer"
shell "github.com/ipfs/go-ipfs-api"
)
// SimpleAsset implements a simple chaincode to manage an asset
type SimpleAsset struct {
}
func (t *SimpleAsset) Init(APIstub shim.ChaincodeStubInterface) peer.Response {
return shim.Success(nil)
}
func (t *SimpleAsset) Invoke(APIstub shim.ChaincodeStubInterface) peer.Response {
// Extract the function and args from the transaction proposal
fn,args := APIstub.GetFunctionAndParameters()
var result string
var err error
if fn == "set-to-ipfs" {
result,err = setToIpfs(APIstub,args)
} else if fn == "get-from-ipfs" {
result,err = getFromIpfs(APIstub,args)
}
if err != nil {
return shim.Error(err.Error())
}
return shim.Success([]byte(result))
}
func setToIpfs(APIstub shim.ChaincodeStubInterface,args []string) (string,error) {
if len(args) != 1 {
return "",fmt.Errorf("Incorrect arguments. Expecting a value")
}
sh := shell.NewShell("ipfs_host:5001")
// ipfs add
cid,err := sh.Add(strings.NewReader(args[0]))
if err != nil {
fmt.Fprintf(os.Stderr,"error: %s",err)
return "",err
}
// show hash
fmt.Println("added ",cid)
if err != nil {
return "",fmt.Errorf("Failed to set asset: %s",args[0])
}
return cid,nil
}
func getFromIpfs(APIstub shim.ChaincodeStubInterface,fmt.Errorf("Incorrect arguments. Expecting a hash")
}
sh := shell.NewShell("ipfs_host:5001")
hashKey := args[0]
// ipfs cat
catResult,err := sh.Cat(hashKey)
defer catResult.Close()
if err != nil {
fmt.Fprintf(os.Stderr,err
}
// read string from buffer
buf := new(bytes.Buffer)
buf.ReadFrom(catResult)
message := buf.String()
return message,nil
}
// main function starts up the chaincode in the container during instantiate
func main() {
if err := shim.Start(new(SimpleAsset)); err != nil {
fmt.Printf("Error starting SimpleAsset chaincode: %s",err)
}
}
但是当我尝试在第一个网络和docker-devmode(甚至无法构建)上执行上述链码时,却收到以下错误消息:
在以下任意位置均找不到软件包github.com/hyperledger/fabric/core/chaincode/shim: /usr/local/go/src/github.com/hyperledger/fabric/core/chaincode/shim(来自$ GOROOT) /go/src/github.com/hyperledger/fabric/core/chaincode/shim(来自$ GOPATH) ipfsfabric.go:29:5:在以下任何位置都找不到软件包“ github.com/hyperledger/fabric/protos/peer”: /usr/local/go/src/github.com/hyperledger/fabric/protos/peer(来自$ GOROOT) /go/src/github.com/github.com/hyperledger/fabric/protos/peer(来自$ GOPATH) 无法加载程序包:程序包github.com/ipfs/go-ipfs-api:在以下任意位置均找不到程序包“ github.com/ipfs/go-ipfs-api”: /opt/go/src/github.com/ipfs/go-ipfs-api(来自$ GOROOT) /opt/gopath/src/github.com/ipfs/go-ipfs-api(来自$ GOPATH)
获取软件包的命令
go get -u github.com/ipfs/go-ipfs-api
go get -u github.com/hyperledger/fabric/protos/peer
go get -u github.com/hyperledger/fabric/core/chaincode/shim
安装go后,我将其添加到了〜。/ profile 文件中:
文件摘录
export PATH=$PATH:/usr/local/go/bin
转到版本
go version go1.14.8 linux/amd64
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。