go mod: 配置代理
一,安装第三方库时报错:
没添加代理时,会报错超时错误
# go get -u github.com/gofiber/fiber/v2
go: module github.com/gofiber/fiber/v2: Get "https://proxy.golang.org/github.com/gofiber/fiber/v2/@v/list":
dial tcp 142.250.217.81:443: i/o timeout
二,解决:
编辑/etc/profile
# vi /etc/profile
添加内容:
export GO111MODULE=on
export GOPROXY=https://goproxy.cn
使生效:
# source /etc/profile
查看效果:
# go env
GO111MODULE='on'
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/data/gopath/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/data/gopath'
GOPRIVATE=''
GOPROXY='https://goproxy.cn'
...
三,再次安装第三方库时可以成功安装:
安装:
# go get -u github.com/gofiber/fiber/v2
go: downloading github.com/gofiber/fiber/v2 v2.52.5
go: downloading github.com/gofiber/fiber v1.14.6
go: downloading github.com/google/uuid v1.5.0
go: downloading github.com/mattn/go-colorable v0.1.13
go: downloading github.com/mattn/go-isatty v0.0.20
go: downloading github.com/mattn/go-runewidth v0.0.15
go: downloading github.com/google/uuid v1.6.0
go: downloading github.com/valyala/bytebufferpool v1.0.0
go: downloading github.com/mattn/go-runewidth v0.0.16
go: downloading github.com/valyala/fasthttp v1.51.0
go: downloading github.com/valyala/fasthttp v1.57.0
go: downloading golang.org/x/sys v0.15.0
go: downloading golang.org/x/sys v0.27.0
go: downloading github.com/rivo/uniseg v0.2.0
go: downloading github.com/rivo/uniseg v0.4.7
go: downloading github.com/andybalholm/brotli v1.0.5
go: downloading github.com/andybalholm/brotli v1.1.1
go: downloading github.com/klauspost/compress v1.17.0
go: downloading github.com/klauspost/compress v1.17.11
go: downloading github.com/valyala/tcplisten v1.0.0
go: added github.com/andybalholm/brotli v1.1.1
go: added github.com/gofiber/fiber/v2 v2.52.5
go: added github.com/google/uuid v1.6.0
go: added github.com/klauspost/compress v1.17.11
go: added github.com/mattn/go-colorable v0.1.13
go: added github.com/mattn/go-isatty v0.0.20
go: added github.com/mattn/go-runewidth v0.0.16
go: added github.com/rivo/uniseg v0.4.7
go: added github.com/valyala/bytebufferpool v1.0.0
go: added github.com/valyala/fasthttp v1.57.0
go: added github.com/valyala/tcplisten v1.0.0
go: added golang.org/x/sys v0.27.0
查看已安装模块:
# go list -m all
industry
github.com/andybalholm/brotli v1.1.1
github.com/gofiber/fiber/v2 v2.52.5
github.com/google/uuid v1.6.0
github.com/klauspost/compress v1.17.11
github.com/mattn/go-colorable v0.1.13
github.com/mattn/go-isatty v0.0.20
github.com/mattn/go-runewidth v0.0.16
github.com/philhofer/fwd v1.1.2
github.com/rivo/uniseg v0.4.7
github.com/tinylib/msgp v1.1.8
github.com/valyala/bytebufferpool v1.0.0
github.com/valyala/fasthttp v1.57.0
github.com/valyala/tcplisten v1.0.0
github.com/xyproto/randomstring v1.0.5
golang.org/x/crypto v0.28.0
golang.org/x/net v0.30.0
golang.org/x/sys v0.27.0
golang.org/x/text v0.19.0