Objective:
with the release of go1.11, go has introduced the Go module to solve the dependency management problem, the Go module is integrated into the native go cmd, but if your code base is in $gopath, the module function of go1.11 is not enabled by default and wants to Open is also very simple, with an environment variable to open go module: export GO111MODULE=on
.
About $GOPROXY
When we use go, go defaults to download the dependent dependencies directly from the codebase, Goproxy this environment variable allows us to control where we can download the source code, and if Goproxy is not set, go will download the dependent code directly from the code base. If you set this environment variable as follows, you will download all the source code through Goproxy.io.
Export goproxy=Https://goproxy.io
You can close the export goproxy= by placing an empty environment variable.
before everyone executedgo get golang.org/x/net
NET code library is downloaded to the local gopath, and any future projects are referenced to thegolang.org/x/net
Will not download this code base, because the local gopath already have, even if the version is not correct, Golang will also reference. But as the module concept introduces the Go language, each introduced module has version. As the code base continues to update iterations, even references to the same code base may use different tags or commit hashes, based on this situation, the go1.11 module will download the source code more frequently than before. But based on China's Chinese-style internet, we sometimes find it difficult to get the dependent source code we need, resulting in project compilation failure and CI failure. So, we need a proxy.
Goproxy.io
Goproxy.io is an open source project, when the user requests a dependent library, if it discovers that the local code will automatically request the source, and then cache to the local, the user can request from the Goproxy.io to the data. Of course, these are all done in a single request. Goproxy.io only supports Go module mode. When the user executes the go get command, it checks the $goproxy/ /@v/list This file has a version that the user wants to get, and if so, get $GOPROXY/ /@v/ . Info, $GOPROXY/ /@v/ . MoD, $GOPROXY/ /@v/ . zip files, if not, directly from the source library to download.
since Go module attaches great importance to security in its design, after enabling go module, you will findgo.mod
In addition to this file, there is ago.sum
file, this file holds the corresponding hash value of each dependent library to ensure that the downloaded code base is correct and not tampered with. At the same time, Goproxy.io is also an open source project. You can deploy yourself to your own IDC, because the company's own code base Goproxy.io is inaccessible. Open Source Address:
htt Ps://github.com/goproxyio/goproxy
References: