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了

相关推荐
千谦阙听几秒前
【C++篇】:string类——常用接口、底层原理与深浅拷贝
开发语言·c++·学习·visual studio
摇滚侠4 分钟前
《Spring Boot 3:高级与架构设计》第 3 章 Bean 的全生命周期原理 Bean 的全生命周期概览 阅读笔记 9
spring boot·笔记·后端
墨家句子11 分钟前
AnythingLLM 搭本地知识库:文档问答不准怎么调
linux·后端
知守观11 分钟前
OBS 同名文件互相覆盖,客户拿错了别人的报告:一次文件串号的排查与重构
java·后端
特立独行的猫A15 分钟前
Godot 游戏编辑器移植鸿蒙 PC:难度与可行性分析
后端·harmonyos
章鱼哥197118 分钟前
DeepSeek Harness 插件开发新手教程
后端·deepseek
特立独行的猫A27 分钟前
C++ 异步编程:std::future 与 std::promise 详解(含 RPC 客户端实现实践)
c++·后端
Anymous32 分钟前
支付为什么要验两次签?——从渠道验签到服务间信任边界与 RSA2
后端
m0_3807438733 分钟前
PHP7.1项目升级到8.3报错怎么解决
开发语言·php
泡海椒1 小时前
JQuick-Excel 字段映射实战:用 MAPPING 固化 Excel 表头与业务字段契约
xml·java·开发语言·excel