Goproxy.io for Go modules

Source: Internet
Author: User

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/netNET code library is downloaded to the local gopath, and any future projects are referenced to thegolang.org/x/netWill 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.modIn addition to this file, there is ago.sumfile, 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:

    • Https://goproxy.io

    • Https://github.com/goproxyio/goproxy

    • Https://research.swtch.com/vgo-intro

    • Https://docs.gomods.io




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.