go get 无法下载问题解决方案及下载 aliyun-oss-go-sdk incompatible.info
生活随笔
收集整理的這篇文章主要介紹了
go get 无法下载问题解决方案及下载 aliyun-oss-go-sdk incompatible.info
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1. 問題現(xiàn)象
由于眾所周知的原因,使用 go get 時往往會速度很慢或者壓根無法下載下來,如下所示:
wohu@wohu:/$ go get -v github.com/aliyun/aliyun-oss-go-sdk/oss
github.com/aliyun/aliyun-oss-go-sdk (download)
Fetching https://golang.org/x/time/rate?go-get=1
https fetch failed: Get https://golang.org/x/time/rate?go-get=1: dial tcp 216.239.37.1:443: i/o timeout
package golang.org/x/time/rate: unrecognized import path "golang.org/x/time/rate" (https fetch: Get https://golang.org/x/time/rate?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)wohu@wohu:/$ go version
go version go1.12.4 linux/amd64
一直提示超時,無法下載安裝。
2. 解決方案
2.1 Go version >= 1.13 (RECOMMENDED)
go env -w GO111MODULE=on
go env -w GOPROXY="https://goproxy.io,direct"# Set environment variable allow bypassing the proxy for selected modules (optional)
go env -w GOPRIVATE="*.corp.example.com"# Set environment variable allow bypassing the proxy for specified organizations (optional)
go env -w GOPRIVATE="example.com/org_name"
2.2 Go version <= 1.12
- Bash (Linux or macOS)
# Enable the go modules feature
export GO111MODULE="on"
# Set the GOPROXY environment variable
export GOPROXY="https://goproxy.io"
或者將以上內(nèi)容寫進(jìn) .profile 或者 .bash_profile 文件。
- PowerShell (Windows)
# Enable the go modules feature
$env:GO111MODULE="on"
# Set the GOPROXY environment variable
$env:GOPROXY="https://goproxy.io"
參考官網(wǎng)教程: https://goproxy.io/
2.3 下載源碼
https://blog.csdn.net/u013536232/article/details/104476356
3. 使用示例
我們以 aliyun-oss-go-sdk 為例,使用步驟 2 中的解決方案后,下載安裝過程如下:
wohu@wohu:/$ export GO111MODULE="on"
wohu@wohu:/$ export GOPROXY="https://goproxy.io"
wohu@wohu:/$ go get -v github.com/aliyun/aliyun-oss-go-sdk/oss
Fetching https://goproxy.io/github.com/aliyun/aliyun-oss-go-sdk/oss/@v/list
Fetching https://goproxy.io/github.com/aliyun/aliyun-oss-go-sdk/@v/list
go: finding github.com/aliyun/aliyun-oss-go-sdk v2.1.2+incompatible
Fetching https://goproxy.io/github.com/aliyun/aliyun-oss-go-sdk/@v/v2.1.2+incompatible.info
go: downloading github.com/aliyun/aliyun-oss-go-sdk v2.1.2+incompatible
Fetching https://goproxy.io/github.com/aliyun/aliyun-oss-go-sdk/@v/v2.1.2+incompatible.zip
go: extracting github.com/aliyun/aliyun-oss-go-sdk v2.1.2+incompatible
Fetching https://goproxy.io/github.com/aliyun/aliyun-oss-go-sdk/@v/v2.1.2+incompatible.mod
Fetching https://goproxy.io/golang.org/x/time/rate/@v/list
Fetching https://goproxy.io/golang.org/x/time/@v/list
go: finding golang.org/x/time latest
Fetching https://goproxy.io/golang.org/x/time/@latest
go: downloading golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
Fetching https://goproxy.io/golang.org/x/time/@v/v0.0.0-20200630173020-3af7569d3a1e.zip
go: extracting golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
Fetching https://goproxy.io/golang.org/x/time/@v/v0.0.0-20200630173020-3af7569d3a1e.mod
golang.org/x/time/rate
github.com/aliyun/aliyun-oss-go-sdk/oss
wohu@wohu:/$
下載完成后將 pkg 目錄下的 aliyun-oss-go-sdk 拷貝到 $GOPATH/src/github.com
運行以下代碼:
package mainimport ("fmt""github.com/aliyun/aliyun-oss-go-sdk/oss"
)func main() {fmt.Println("OSS Go SDK Version: ", oss.Version)
}
輸出:
OSS Go SDK Version: v2.1.2
總結(jié)
以上是生活随笔為你收集整理的go get 无法下载问题解决方案及下载 aliyun-oss-go-sdk incompatible.info的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。