一,安裝第三方庫時報錯:
沒新增代理時,會報錯超時錯誤
# 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