這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。
Hyperledger Fabric Client SDK for Go
go get -u github.com/hyperledger/fabric-sdk-go
文檔 https://godoc.org/github.com/hyperledger/fabric-sdk-go
相容性
- fabric v1.0.1 & fabric-ca v1.0.1
- fabric-sdk-go: master:HEAD
- fabric v1.0.0 & fabric-ca v1.0.0
- fabric-sdk-go: master:110bf21bf3ab0a9a084f46d9698e1daeeda68a59
運行整體測試cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/
make depend-install一些包無法go get到,只能git clone
make在Makefile檔案中,執行dep ensure -vendor-only時報錯
原因是godep工具根據Gopkg.toml中name配置尋找包源的時候,name和包的git地址不一致,譬如name: google.golang.org/grpcgit : https://github.com/grpc/grpc-go
name: golang.org/x/crypto
git https://github.com/golang/crypto
name: golang.org/x/sync
git https://github.com/golang/sync
name: golang.org/x/net
git: https://github.com/golang/net
添加source配置也無效,在github上的問題追蹤https://github.com/golang/dep/issues/860目前在Makefile中去掉"populate",不去處理vendor問題,而使用GOPATH下的依賴包
make clean
運行部分測試
# In the Fabric SDK Go directorycd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/# Ensure dependencies are installedmake depend# Running code checks (license, linting, spelling, etc)make checks# Running all unit testsmake unit-test# Running all integration testsmake integration-test沒有太好的辦法,網路問題,需要多次嘗試報錯:
原因是在docker compose檔案中,映射目錄時,將本地fabric-sdk-go目錄映射到容器的fabric-sdk-go目錄,依賴包採用的是vendor中包
手動將$GOPATH下的依賴包拷貝到fabric-sdk-go/vendor中再次運行
make integration-test
用docker開啟fabric網路測試環境
Testing with Local Build of Fabric (Advanced)
Alternatively you can build and run Fabric on your own box using the following commands:
# Build fabric:
cd $GOPATH/src/github.com/hyperledger/
git clone https://github.com/hyperledger/fabric
cd $GOPATH/src/github.com/hyperledger/fabric/
git checkout v1.0.1
make docker
本地鏡像的tag與要求不匹配,需要手動修改鏡像的tag REPOSITORY
docker tag imageId repository:tag
# Build fabric-ca:
cd $GOPATH/src/github.com/hyperledger/
git clone https://github.com/hyperledger/fabric-ca
cd $GOPATH/src/github.com/hyperledger/fabric-ca/
git checkout v1.0.1
make docker
# Start fabric - latest-env.sh overrides the default docker tags in .env
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/
(source latest-env.sh && docker-compose up --force-recreate)