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

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/

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 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
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值