解决go mod vendor 报错io/fs is not in GOROOT问题

在Linux环境下开发Go项目时,遇到使用viper v1.8.1版本时,由于该版本依赖Go 1.16.5,而当前系统中是Go 1.15.8,导致gomodvendor执行失败。解决方案包括升级Go版本至1.16.5或降级viper版本。升级步骤涉及下载新版本、更新环境变量并验证版本变更,然后重新执行gomodvendor。另一种方案是寻找与现有Go版本兼容的viper低版本。

问题背景

在linux 系统下开发go项目


项目场景:

在linux 系统下开发go项目,当前go版本: go1.15.8

项目中需要使用viper组件,viper版本v1.8.1

go项目使用go mod 模式编译


问题描述:

1.执行go mod vendor时报错:

github.com/spf13/viper imports

github.com/spf13/afero imports

io/fs: package io/fs is not in GOROOT(usr/local/go/src/io/fs)

go build 


原因分析:

viper v1.8.1依赖更高版本的go版本: v1.16.5
 


解决方案:

方案一:

1.下载go版本v1.16.5

2.解压到指定目录,如$HOME

3.编辑$HOME/.bashrc ,添加:

        export PATH=$HOME/go/bin:$PATH

4.生效:

        source ~/.bashrc

5. 查看go 版本是否是v1.16.5

        go version

6.重新执行go mod vendor,问题得到解决。

方案二:

使用更低版本的viper。

  

root@ubuntu:/home/uu/go/src/github.com/hyperledger/fabric-samples/test-network# sudo ./network.sh deployCC Using docker and docker-compose deploying chaincode on channel 'mychannel' executing with the following - CHANNEL_NAME: mychannel - CC_NAME: basic - CC_SRC_PATH: ../asset-transfer-basic/chaincode-go - CC_SRC_LANGUAGE: go - CC_VERSION: 1.0 - CC_SEQUENCE: auto - CC_END_POLICY: NA - CC_COLL_CONFIG: NA - CC_INIT_FCN: NA - DELAY: 3 - MAX_RETRY: 5 - VERBOSE: false executing with the following - CC_NAME: basic - CC_SRC_PATH: ../asset-transfer-basic/chaincode-go - CC_SRC_LANGUAGE: go - CC_VERSION: 1.0 Vendoring Go dependencies at ../asset-transfer-basic/chaincode-go /home/uu/go/src/github.com/hyperledger/fabric-samples/asset-transfer-basic/chaincode-go /home/uu/go/src/github.com/hyperledger/fabric-samples/test-network /home/uu/go/src/github.com/hyperledger/fabric-samples/test-network Finished vendoring Go dependencies + '[' false = true ']' + peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go --lang golang --label basic_1.0 + res=0 Chaincode is packaged Installing chaincode on peer0.org1... Using organization 1 + peer lifecycle chaincode queryinstalled --output json + jq -r 'try (.installed_chaincodes[].package_id)' + grep '^Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|approveformyorg|queryapproved|checkcommitreadiness|commit|querycommitted Usage: peer lifecycle chaincode [command] Available Commands: approveformyorg Approve the chaincode definition for my org. checkcommitreadiness Check whether a chaincode definition is ready to be committed on a channel. commit Commit the chaincode definition on the channel. getinstalledpackage Get an installed chaincode package from a peer. install Install a chaincode. package Package a chaincode queryapproved Query an org'\''s approved chaincode definition from its peer. querycommitted Query the committed chaincode definitions by channel on a peer. queryinstalled Query the installed chaincodes on a peer. Flags: --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint --clientauth Use mutual TLS when communicating with the orderer endpoint --connTimeout duration Timeout for client to connect (default 3s) -h, --help help for chaincode --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint -o, --orderer string Ordering service endpoint --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer --tls Use TLS when communicating with the orderer endpoint --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint Use "peer lifecycle chaincode [command] --help" for more information about a command.$' + test 1 -ne 0 + peer lifecycle chaincode install basic.tar.gz + res=1 Error: chaincode install failed with status: 500 - failed to invoke backing implementation of 'InstallChaincode': could not build chaincode: docker build failed: docker image build failed: docker build failed: Error returned from build: 1 "vendor/google.golang.org/protobuf/internal/editiondefaults/defaults.go:9:8: cannot find package "." in: /chaincode/input/src/vendor/embed vendor/golang.org/x/net/http2/transport.go:19:2: cannot find package "." in: /chaincode/input/src/vendor/io/fs vendor/google.golang.org/grpc/stats/metrics.go:19:8: cannot find package "." in: /chaincode/input/src/vendor/maps vendor/google.golang.org/grpc/balancer/pickfirst/internal/internal.go:22:2: cannot find package "." in: /chaincode/input/src/vendor/math/rand/v2 vendor/google.golang.org/grpc/balancer/pickfirst/pickfirstleaf/pickfirstleaf.go:33:2: cannot find package "." in: /chaincode/input/src/vendor/net/netip vendor/google.golang.org/grpc/clientconn.go:27:2: cannot find package "." in: /chaincode/input/src/vendor/slices " Chaincode installation on peer0.org1 has failed Deploying chaincode failed
06-12
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值