others-how to solve golang download required package error:reading https://mirrors.aliyun.com/goproxy/modernc.org/cc/@v/v1.0.0.mod: 404 Not Found ?

Problem

When we install a golang sdk, sometime, we get this error:

INFO[0000] Created pkg/controller/controller.go         
INFO[0000] Created version/version.go                   
INFO[0000] Created .gitignore                           
INFO[0000] Validating project                           
go: github.com/operator-framework/[email protected] requires
    k8s.io/[email protected] requires
    gonum.org/v1/[email protected] requires
    modernc.org/[email protected]: reading https://mirrors.aliyun.com/goproxy/modernc.org/cc/@v/v1.0.0.mod: 404 Not Found
Error: failed to exec []string{"go", "build", "./..."}: exit status 1

The core error is :

reading https://.../modernc.org/cc/@v/v1.0.0.mod: 404 Not Found

Why the golang can not find the required module?

Environment

  • MacOS 10.14
  • Golang go version go1.14 darwin/amd64

Reason

We are using a goproxy that caused the access 404 problem, we should use the goproxy.io golang proxy:

The goproxy.io is one of the world’s earliest Go modules mirror proxy services, developed and maintained by a group of young people who love open source and the Go language. Since go 1.11, the go language has supported go modules to solve the long-standing complaint about dependency management. At present, this feature have met the production environment standards.

image-20201214210512553

Solution

We should change the goproxy to the offical goproxy as follows:

go env -w  GOPROXY=https://goproxy.io

Then ,we can verify the proxy settings as follows:

go env|grep proxy

One more thing

We can set the go proxy with more options:

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"

Then try again to install the sdk, It works!