go moudle模块加载被墙解决方法
发布日期:2021-05-08 13:57:01 浏览次数:18 分类:精选文章

本文共 1784 字,大约阅读时间需要 5 分钟。

go moudle 为golang的一种包管理方式;而对于在国内使用,很多外网的包可能会无法使用,遂做一个记录;

报错信息:

go: golang.org/x/crypto@v0.0.0-20190701094942-4def268fd1a4: unrecognized import path "golang.org/x/crypto" (https fetch: Get https://golang.org/x/crypto?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)go: golang.org/x/sys@v0.0.0-20190813064441-fde4db37ae7a: unrecognized import path "golang.org/x/sys" (https fetch: Get https://golang.org/x/sys?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)go: golang.org/x/sys@v0.0.0-20190222072716-a9d3bda3a223: unrecognized import path "golang.org/x/sys" (https fetch: Get https://golang.org/x/sys?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)

对于golang.org/x/**下的包,由于墙的原因,无法更新;解决方案如下:

方法1:
根据需要的版本号,如果不清楚,可以使用 v0.0.0 ,执行命令, 可以用github上的镜像地址替换:

go mod edit -require=golang.org/x/***@v0.0.0go mod edit -replace=golang.org/x/***@v0.0.0=github.com/golang/***@latest

方法1设置后,go.mod文件中显示如下:

go 1.12require golang.org/x/*** v0.0.0replace golang.org/x/*** v0.0.0 => github.com/golang/*** latest

方法2:

配置代理地址:,在idea中可以直接配置go moudle的代理地址为这个url;
如果你使用的 Go 版本>=1.13, 你可以通过设置 GOPRIVATE 环境变量来控制哪些私有仓库和依赖(公司内部仓库)不通过 proxy 来拉取,直接走本地,设置如下:

go env -w GOPROXY=https://goproxy.io,direct# 设置不走 proxy 的私有仓库,多个用逗号相隔go env -w GOPRIVATE=*.corp.example.com
上一篇:golang内存及GC分析简易方法
下一篇:消息引擎/kafka简介

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2025年04月19日 08时18分38秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章