Preface
go get is used to dynamically obtain remote code packages. Currently, it supports BitBucket, GitHub, Google Code and Launchpad. This command is actually divided into two steps internally: the first step is to download the source code package, and the second step is to execute go install. The go tool that downloads the source code package will automatically call different source code tools according to different domain names, and the corresponding relationship is as follows:
- BitBucket (Mercurial Git)
- GitHub (Git)
- Google Code Project Hosting (Git, Mercurial, Subversion)
- Launchpad (Bazaar)
Go get parameter description:
- -d only download but not install
- -f is only valid when you include the -u parameter. Don't let -u verify that every one of the import has been retrieved. This is especially useful for local fork packages
- -fix After obtaining the source code, run fix first, and then do other things
- -t Also download the packages required to run the tests
- -u Force the network to update the package and its dependency package
- -v Show the executed command
Notice:The –v parameter here is very helpful for us to analyze the problem.
But everyone who has used it knows that go get has a weak function and cannot get branches, tags, specific versions, fork, and dep can do it. dep can also get private libraries.
Use dep instead of go get to get private library
Use private library for testing. Create gogettest library.
Available:
go get -u /jinq0123/gogettest
If changed to private library, it fails:
λ go get -v /jinq0123/gogettest Fetching /jinq0123/gogettest?go-get=1 Parsing meta tags from /jinq0123/gogettest?go-get=1 (status code 403) package /jinq0123/gogettest: unrecognized import path "/jinq0123/gogettest" (parse /jinq0123/gogettest?go-get=1: no go-import meta tags ())
Use the dep tool to get private libraries
/golang/dep
Install dep
go get -u /golang/dep/cmd/dep
initialization
Run in the project directory:
dep init
Generate and
Add a constraint
Add in :
[[constraint]]
branch = "master"
name = "/jinq012345/gogettest"
source = /jinq0123/
source Force https to get the getgettest library.
Note that the library name has been changed to jinq012345, import it like this:
imort "/jinq012345/gogettest"
The name and source settings can be obtained from the fork library.
Get gogettest library
dep ensure
The login username and password input box for https will pop up.
Summarize
The above is the entire content of this article. I hope that the content of this article has certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.