For the following compilation error:
go build -o hello main.go
build command-line-arguments: cannot load google.golang.org/grpc: module google.golang.org/grpc: Get https://proxy.golang.org/google.golang.org/grpc/@v/list: dial tcp 172.217.24.17:443: i/o timeout
There are two solutions:
1 agent approach
Which is to set the environment variable "GOPROXY" and "Before the implementation of GO111MODULE ":
export GO111MODULE=on
export GOPROXY=https://goproxy.io或者export GOPROXY=https://goproxy.cn
For the 1.13 and above and can be used directly in the following manner:
go env -w GOPROXY=https://goproxy.cn,direct
We recommended seven cattle cloud "goproxy.cn" , because "goproxy.io" is not necessarily available.
Automatically download the package is placed in the user's home directory, the full path: ~ / go / pkg / mod, such as:
$ls -l ~/go/pkg/mod
total 0
drwxr-xr-x 4 guest staff 128 2 21 14:11 cache
drwxr-xr-x 3 guest staff 96 2 21 14:11 github.com
drwxr-xr-x 3 guest staff 96 2 21 14:11 golang.org
drwxr-xr-x 4 guest staff 128 2 21 14:11 google.golang.org
If you experience the following error:
go: downloading google.golang.org/grpc v1.27.1
build command-line-arguments: cannot load google.golang.org/grpc: open /Users/guest/go/pkg/mod/cache/download/google.golang.org/grpc/@v/v1.27.1.lock: permission denied
Please add in the implementation of "sudo" , such as:
sudo go build -o hello hello.go
2 using the "go mod" a "replace" command, the local path into a network path, such as:
$cat go.mod
module hello
go 1.13
require google.golang.org/grpc v1.27.1 // indirect
replace google.golang.org/grpc => /usr/local/go/src/google.golang.org/grpc
Note, the replace the need to appear in require of.