首页 > 解决方案 > Hyperledger Fabric 未按照其文档工作

问题描述

使用 MacBook Pro、Big Sur 操作系统,我按照 hyperledger fabric文档,安装了所有必需的文件和工具。但是,当我到达最后一步时,代码生成了一个我无法修复的 goimports 错误。错误如下:

johnny@JohnnyMBP fabric % make basic-checks integration-test-prereqs
All files are excluded from having license headers
Building github.com/client9/misspell/cmd/misspell -> misspell
Checking changed go files for spelling errors ...
spell checker passed
Checking for go:generate parent path references
Checking trailing spaces ...
DEP: Checking for dependency issues..
./scripts/check_deps.sh
Building golang.org/x/tools/cmd/goimports -> goimports
Building mvdan.cc/gofumpt -> gofumpt
Building honnef.co/go/tools/cmd/staticcheck -> staticcheck
LINT: Running code checks..
./scripts/golinter.sh
Checking with goimports
The following files contain goimports errors
bccsp/factory/nopkcs11.go
bccsp/factory/nopkcs11_test.go
bccsp/factory/pkcs11.go
bccsp/factory/pkcs11_test.go
bccsp/factory/pkcs11factory.go
bccsp/factory/pkcs11factory_test.go
bccsp/pkcs11/pkcs11_test.go
core/handlers/library/noplugin_test.go
core/handlers/library/plugin.go
core/handlers/library/plugin_stub.go
core/handlers/library/race_test.go
integration/ledger/ledger_generate_test.go
internal/fileutil/syncdir.go
internal/peer/node/signals.go
internal/peer/node/signals_windows.go
orderer/common/server/signals.go
orderer/common/server/signals_windows.go
The goimports command 'goimports -l -w' must be run for these files
make: *** [linter] Error 1
johnny@JohnnyMBP fabric % 

这是我的 go 环境结果:

johnny@JohnnyMBP fabric % go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/johnny/Library/Caches/go-build"
GOENV="/Users/johnny/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/johnny/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/johnny/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.17.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.17.2/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/johnny/github.com/webzest/fabric/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/vs/8twtz6352nb26pnpyqfk11j80000gn/T/go-build698966046=/tmp/go-build -gno-record-gcc-switches -fno-common"

请提供一些指导,我可以遵循这些指导来完成超级账本结构的开发环境。

更新:

我对所有 .go 文件运行 goimports -l -w 并重新运行 make basic-check。现在,我收到供应商错误:

johnny@JohnnyMBP fabric % make basic-checks
All files have SPDX-License-Identifier headers
Building github.com/client9/misspell/cmd/misspell -> misspell
Checking changed go files for spelling errors ...
spell checker passed
Checking for go:generate parent path references
Checking trailing spaces ...
DEP: Checking for dependency issues..
./scripts/check_deps.sh
Building golang.org/x/tools/cmd/goimports -> goimports
Building mvdan.cc/gofumpt -> gofumpt
Building honnef.co/go/tools/cmd/staticcheck -> staticcheck
LINT: Running code checks..
./scripts/golinter.sh
Checking with goimports
Checking with gofumpt
Checking for golang.org/x/net/context
Checking for github.com/gogo/protobuf
Checking with go vet
Checking with staticcheck
The following staticcheck issues were flagged
vendor/github.com/dustin/go-humanize/number.go:76:9: constant  overflow (compile)
vendor/github.com/onsi/ginkgo/internal/leafnodes/benchmarker.go:82:25: constant  overflow (compile)
make: *** [linter] Error 1
johnny@JohnnyMBP fabric % 

有没有人使用最新版本的 GO 和最新版本的 GIT for Fabric 成功设置开发环境?我需要帮助,好吗?

标签: hyperledger-fabric

解决方案


有两件事要尝试:

  • 使用 Go 1.16(这是当前用于构建/运行 Fabric 的版本)。
  • 使用官方安装程序安装到 /usr/local/go 的 Go,而不是使用 Homebrew 安装。

如果这些文件中的导入确实有问题,除非它们已在本地进行了修改,否则不应该有问题,请goimports -l -w对列出的每个文件使用命令来更正它们。

作为参考,我也在使用 Macbook Pro,运行 MacOS Monterey,但之前使用 Big Sur,并且在最新的分支代码make basic-checks上使用 Go 1.16.9 为我干净地运行。


推荐阅读