go mod tidy 报错:x509: certificate signed by unknown authority 最佳实践

最近在docker中运行了一个ubuntu20的系统,在上面运行golang程序,使用go mod tidy后报错:

tls: failed to verify certificate: x509: certificate signed by unknown authority

如:

bash 复制代码
go: finding module for package google.golang.org/grpc/credentials/insecure
go: finding module for package github.com/shopspring/decimal
go: finding module for package github.com/stretchr/testify/assert
go: metag_media_server/app imports
	github.com/gin-gonic/gin: module github.com/gin-gonic/gin: Get "https://goproxy.cn/github.com/gin-gonic/gin/@v/list": tls: failed to verify certificate: x509: certificate signed by unknown authority
go: metag_media_server/app/config imports
	github.com/pkg/errors: module github.com/pkg/errors: Get "https://goproxy.cn/github.com/pkg/errors/@v/list": tls: failed to verify certificate: x509: certificate signed by unknown authority
go: metag_media_server/app/config imports
	github.com/spf13/viper: module github.com/spf13/viper: Get "https://goproxy.cn/github.com/spf13/viper/@v/list": tls: failed to verify certificate: x509: certificate signed by unknown authority
go: metag_media_server/app/controller imports
	github.com/axetroy/go-fs: module github.com/axetroy/go-fs: Get "https://goproxy.cn/github.com/axetroy/go-fs/@v/list": tls: failed to verify certificate: x509: certificate signed by unknown authority
go: metag_media_server/app/controller imports

出现这中情况一般都是自己安装全新的ubuntu系统,或者在docker中安装ubuntu镜像,跟我一样。

在网上找了很多资料,都没有解决。

这里提供两种最佳方案:

一:设置http的goproxy

bash 复制代码
export GOPROXY=http://goproxy.cn

或者

export GOPROXY=http://mirrors.aliyun.com/goproxy/

注意前缀不是https

二:重装ca-certificates

bash 复制代码
sudo apt-get install --reinstall ca-certificates
sudo apt-get update

之后就可以愉快的使用go mod tidy了

相关推荐
小小鱼儿飞2 分钟前
QT Quick QML项目音乐播放器16----无边框窗口拖动、小窗播放、隐藏系统托盘
开发语言·qt
-指短琴长-6 分钟前
Qt的下载和安装【Windows】
开发语言·windows·qt
不会编程的小寒7 分钟前
C++ this指针、常函数、内联函数
java·开发语言
小冯的编程学习之路11 分钟前
【C++】:C++基于微服务的即时通讯系统(2)
开发语言·c++·微服务
观望过往26 分钟前
Spring Boot 集成 EMQ X 4.0 完整技术指南
java·spring boot·后端·emqx
许长安27 分钟前
C/C++中的extern关键字详解
c语言·开发语言·c++·经验分享·笔记
心之语歌38 分钟前
对于 时间复杂度和空间复杂度分析
后端
青旬42 分钟前
AI编程祛魅-最近几个失败的ai编程经历
后端·程序员
莹Innsane1 小时前
记一次 float64 排序失效的灵异事件
后端
Python私教1 小时前
使用 SQLAlchemy 操作单表:以 SQLite 用户表为例的完整实战指南
后端