记录一个Goland导包失败问题解决办法

一、问题背景
我的Go项目里面要对接阿里的支付功能,需要导入相关的包
github.com/smartwalle/alipay/v3

二、问题现象
按照https://github.com/smartwalle/alipay/tree/master的提示,使用命令
go get github.com/smartwalle/alipay/v3
一直报错提示“go: module github.com/smartwalle/alipay@upgrade found (v1.0.2), but does not contain package github.com/smartwalle/alipay/v3”

三、寻找原因
1.开始以为是我的go版本太低,本地安装的Go1.17, 于是升级到了Go1.20, 但是依然无法导入github.com/smartwalle/alipay/v3
2.在我使用go mod tidy 时发现包来自于:https://mirrors.aliyun.com/goproxy/
, 日志如下:
PS C:\goproject1> go mod tidy
goproject1/controller imports
github.com/gin-gonic/gin imports
github.com/gin-gonic/gin/binding imports
google.golang.org/protobuf/proto imports
google.golang.org/protobuf/reflect/protoregistry tested by
google.golang.org/protobuf/reflect/protoregistry.test imports
github.com/google/go-cmp/cmp/cmpopts imports
golang.org/x/xerrors loaded from golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543,
but go 1.16 would select v0.0.0-20200804184101-5ec99f83aff1
goproject1/controller imports
github.com/gin-gonic/gin imports
github.com/gin-gonic/gin/binding imports
https://mirrors.aliyun.com/goproxy/

一直记得自己配置过go env -w GOPROXY=https://goproxy.cn,而且不曾手动修改这个配置

四、解决办法
重新配置go env 的proxy,操作如下:
PS C:\goproject1> go env -w GOPROXY=https://goproxy.cn
PS C:\goproject1> go env GOPROXY
https://goproxy.cn
PS C:\goproject1> go env GOPROXY
https://goproxy.cn
然后加载github.com/smartwalle/alipay/v3
PS C:\goproject1> go get github.com/smartwalle/alipay/v3
go: downloading github.com/smartwalle/alipay/v3 v3.1.8
go: downloading github.com/smartwalle/crypto4go v1.0.2
go: added github.com/smartwalle/alipay/v3 v3.1.8
go: added github.com/smartwalle/crypto4go v1.0.2
PS C:\goproject1>

操作成功

五、分析原因
https://mirrors.aliyun.com/goproxy/的库中应该是没有alipay的v3版本,而https://goproxy.cn中有此版本。
事后搜索了相关原因,在下面这篇文章中也有类似问题,解决方法相同:
https://blog.csdn.net/shupili141005/article/details/127803546

遗憾的是暂且未找到go env从https://goproxy.cn变更到https://mirrors.aliyun.com/goproxy/的原因,想不起来自己什么时候修改了这个配置

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值