Methods tutorial for getting private libraries using dep instead of go get

  • 2020-06-12 09:23:01
  • OfStack

preface

go get is used to dynamically retrieve remote code packages. Currently supported are BitBucket, GitHub, Google Code and Launchpad. Internally, this command is actually split into two steps: Step 1 is to download the source package, and step 2 is to execute go install. The go tool that downloads the source package automatically invokes different source tools according to different domain names, and the correspondence is as follows:

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

Parameters of go get:

-d download only and do not install -f is only valid if you include the -u parameter. Do not let -u verify that every one of import has been fetched, which is particularly useful for packages with native fork -ES28en Runs fix after obtaining the source code, and then does anything else -ES30en also downloads the packages needed to run the tests -ES31en forces the use of the network to update packets and their dependencies -ES32en displays the command executed

Note: The v parameter here is very helpful for us to analyze the problem.

But as anyone who has used it knows, go get is weak, can't get branches, tags, specific versions, fork, and dep can do that. dep can also get private libraries.

Use dep instead of go get to get the private library

Test with the gitee.ES51en private library. Create the gogettest library.

Available:


go get -u gitee.com/jinq0123/gogettest

If you change to a private library, it fails:


 Lambda.  go get -v gitee.com/jinq0123/gogettest
Fetching https://gitee.com/jinq0123/gogettest?go-get=1
Parsing meta tags from https://gitee.com/jinq0123/gogettest?go-get=1 (status code 403)
package gitee.com/jinq0123/gogettest: unrecognized import path "gitee.com/jinq0123/gogettest" (parse https://gitee.com/jinq0123/gogettest?go-get=1: no go-import meta tags ())

Use the dep tool to get to the private library

https://github.com/golang/dep

Install dep


go get -u github.com/golang/dep/cmd/dep

Initialize the

Run under the project directory:


dep init

Generate Gopkg. toml and Gopkg. lock

Add compulsion (constraint)

Add to ES85en.toml:


[[constraint]]
 branch = "master"
 name = "gitee.com/jinq012345/gogettest"
 source = https://gitee.com/jinq0123/gogettest.git

source forces the use of https to obtain the gotgettest library.

Note that the library name has been changed to jinq012345 to import:


imort "gitee.com/jinq012345/gogettest"

The name and source Settings support fetching from the fork library.

Get gogettest library


dep ensure

A login username and password entry box for https pops up.

conclusion


Related articles: