Go get Get golang.org project

Source: Internet
Author: User
Tags mercurial
This is a creation in Article, where the information may have evolved or changed.

Go get is used to dynamically get remote code packages, currently supported by BitBucket, GitHub, Google code and launchpad. This command is actually divided into two steps inside: The first step is to download the source package, the second step is to execute go install. Download the source package of the Go tool will automatically according to different domain names to invoke different source tools, the corresponding relationship is as follows:

BitBucket (Mercurial Git)
GitHub (Git)
Google Code Project Hosting (Git, Mercurial, Subversion)
Launchpad (Bazaar)

Parameter description for Go get:

-D only download does not install
-F is only valid if you include the-u parameter, and you are not allowed to verify that each of the import has been acquired, which is particularly useful for local fork packages
-fix run fix before you get the source code, and then do something else.
-T also downloads the packages needed to run the test
-U enforces the use of the network to update the package and its dependent packages
-V Show executed commands
Note that the –v parameter here is helpful for us to analyze the problem.

Reference: HTTPS://GITHUB.COM/ASTAXIE/BUILD-WEB-APPLICATION-WITH-GOLANG/BLOB/MASTER/ZH/01.3.MD

Domestic because of the wall, we will receive unrecognized import path error, how can we execute go get through the command line?
At this point we will get an error similar to the following:

Go get-u-v golang.org/x/oauth2
Fetching Https://golang.org/x/oauth2?go-get=1
HTTPS fetch failed.
Import "Golang.org/x/oauth2": HTTPS fetch:get https://golang.org/x/oauth2?go-get=1:dial TCP 216.58.221.145:443:i/o Timeout
Package golang.org/x/oauth2:unrecognized Import Path "Golang.org/x/oauth2"
localhost:~ ghj1976$

If there is a previous version of the directory, the following is true:

Go get-u-v golang.org/x/oauth2
Fetching Https://golang.org/x/oauth2?go-get=1
HTTPS fetch failed.
Import "Golang.org/x/oauth2": HTTPS fetch:get https://golang.org/x/oauth2?go-get=1:dial TCP 216.58.221.145:443:i/o Timeout
Golang.org/x/oauth2 (Download)
Fetching Https://golang.org/x/net/context?go-get=1
HTTPS fetch failed.
Import "Golang.org/x/net/context": HTTPS fetch:get https://golang.org/x/net/context?go-get=1:dial TCP 216.58.221.145:443:I/O Timeout
Golang.org/x/net (Download)
Fetching Https://golang.org/x/oauth2/internal?go-get=1
HTTPS fetch failed.
Import "golang.org/x/oauth2/internal": HTTPS fetch:get https://golang.org/x/oauth2/internal?go-get=1:dial TCP 216.58.221.145:443:I/O Timeout
Golang.org/x/net/context
Golang.org/x/oauth2/internal
Golang.org/x/oauth2
localhost:~ ghj1976$

At this point we need to set up agents. Agent tool I recommend using lantern Https://github.com/getlantern/lantern

It is important to note that http://127.0.0.1:16823/, the latter one, is the site address of its configuration.

In the case of Mac, set up a network proxy in the command line Terminal, the general method is as follows:

root@ed27c545f7af:~# cat ~/proxy.conf export http_proxy=http://172.17.42.1:8118export https_proxy=$http_proxyexport ftp_proxy=$http_proxyexport rsync_proxy=$http_proxyexport no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"

Reference: https://github.com/tools/godep/issues/154

Win under the Set agent export, reference Https://groups.google.com/forum/#!topic/lantern-users-zh/FiywFrEHSHE

Delete environment variables with

Delete: unset variable name reference http://blog.csdn.net/debug_cpp/article/details/2679991

https://code.google.com/p/go/issues/detail?id=2919

After this step agent is set up, we can use the wget command to test the effect. Reference: https://github.com/getlantern/lantern/issues/3341

In addition, the git, mercurial, and SVN settings agents used by Go get refer to:

Https://github.com/golang/go/wiki/GoGetProxyConfig

Take our most commonly used git as an example,

In Terminal settings:
git config--global http.proxy http://127.0.0.1:1080
git config--global https.proxy https://127.0.0.1:1080

The proxy is not set by default:
git config--global--unset http.proxy
git config--global--unset https.proxy

To view the values that have been set:

git config http.proxy

Reference: http://blog.csdn.net/dengbin9009/article/details/38058153

After the configuration is complete, to download golang.org/x/net as an example, the following return values are performed:

Go get-u-v golang.org/x/net
Fetching Https://golang.org/x/net?go-get=1
Parsing meta tags from https://golang.org/x/net?go-get=1 (status code 200)
Get "golang.org/x/net": Found meta tag main.metaimport{prefix: "Golang.org/x/net", VCS: "Git", Reporoot: "https:// Go.googlesource.com/net "} at Https://golang.org/x/net?go-get=1
Golang.org/x/net (Download)
Package Golang.org/x/net:no buildable Go source Files in/users/ghj1976/project/mygocode/src/golang.org/x/net
Localhost:text ghj1976$

We can see in fact is to https://go.googlesource.com/text/such address to download the source code. The middle involves jump and git download, so be aware that the http_proxy of the network request and the GIT agent need to be set.

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.