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了

相关推荐
小徐敲java3 分钟前
python的FastAPI框架
开发语言·python·fastapi
徐行code4 分钟前
C++核心机制-复制消除
后端
lsx2024067 分钟前
CSS3 分页设计指南
开发语言
CHANG_THE_WORLD17 分钟前
Python 切片操作全面解析
开发语言·python
不会代码的小猴19 分钟前
C++的第十二天笔记
开发语言·c++·笔记
开心猴爷20 分钟前
在 CICD 中实践 Fastlane + Appuploader 命令行,构建可复制的 iOS 自动化发布流程
后端
一 乐32 分钟前
高校评教|基于SpringBoot+vue高校学生评教系统 (源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·学习
Boop_wu34 分钟前
[Java EE] 字符流和字节流实例
java·开发语言·apache
shangjian0071 小时前
Python基础-闭包和装饰器
开发语言·python
疯狂的程序猴1 小时前
Web 抓包完整实践指南,从浏览器网络调试到底层数据流捕获的全流程方案
后端