go get 无法下载问题解决方案及下载 aliyun-oss-go-sdk incompatible.info

    技术2025-09-27  53

    1. 问题现象

    由于众所周知的原因,使用 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"

    或者将以上内容写进 .profile 或者 .bash_profile 文件。

    PowerShell (Windows) # Enable the go modules feature $env:GO111MODULE="on" # Set the GOPROXY environment variable $env:GOPROXY="https://goproxy.io"

    参考官网教程: https://goproxy.io/

    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 main import ( "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
    Processed: 0.010, SQL: 9