Introduction to go get command

Time:2021-1-19

Go code is hosted in Github.com Site, the site is based on git code management tools, many famous projects are hosted in the site code. There are other similar hosting sites code.google.com 、 bitbucket.org And so on.

There is a common standard for the project package path of these websites, as shown in the figure below.

 

 

The go get command can pull or update the code package and its dependent packages remotely with the help of code management tools, and complete the compilation and installation automatically. The whole process is as simple as installing an app.

This command can dynamically obtain remote code packages. Currently, bitbucket, GitHub, Google Code and launchpad are supported. Before using the go get command, you need to install code management tools that match the remote package, such as git, SVN, Hg, and so on. You need to provide a package name in the parameters.

This command is actually divided into two steps: 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 package will automatically call different source tools according to different domain names. The corresponding relationship is as follows:

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

Parameter introduction:

-u It is used to download the specified path package and its dependent packages. By default, it will not download the local existing packages, but only download the local nonexistent code packages. It’s a commonly used update package, such as go get – U github.com/jinzhu/gorm . Will download the latest Gorm package to your local
-d This command only downloads the path package, not installs it. That is, the go install command is not executed
-t Let the command program download and install the code package in the specified code package at the same time
-fix After downloading the code package, the command program performs the correction action first, and then compiles and installs. For example, my code was developed with 1.7, and now the go version is 1.13. Some packages have changed, so we can add the – fix tag when we use the go get command. After checking out the code package, this tag first corrects the syntax of the code package that does not conform to the language specification of go 1.7, then downloads its dependent packages, and finally compiles and installs them.
-insecure Allows the command program to use non secure scheme (such as HTTP) to download the specified code package. If your code repository (such as gitlab in your company) doesn’t support HTTPS, you can add this tag. Please use it when you are sure it is safe. (remember when using git, there is a version that HTTP is upgraded to HTTPS.)
-v Print out the names of the downloaded packages
-f Valid only when using the – U tag. This flag causes the command program to ignore checking the import path of the downloaded code package. This is especially important if the downloaded and installed code package belongs to a project that you fork over from someone else
-x Print out the commands used in the whole process

 

  • Where is the package of go get download stored? Generally, it will be saved in this directory: $gopath / SRC. If you have more than one gopath (workspace), it will be saved in the first workspace. Before getting, make sure gopath is set. After go 1.8, gopath is in the go folder of the user directory by default.
  • After go get checks out or updates the code package, it looks for the tag or branch corresponding to the version number of the locally installed go language. For example, if the version of go installed locally is 1. X, the go get command will look for a tag or branch named “go1” in the remote repository of the code package. If the specified label or branch is found, the version of the local code package is switched to this label or branch. If the specified label or branch is not found, the version of the local package is switched to the latest version of the trunk.
  • Go get updates the code package. After changing the code package, other code blocks referenced by this package will be updated when they are used. However, the code in the vendor directory will not be updated.

Recommended Today

Jupyterlab environment of tensorflow

Tensorflow prepares jupyterlab interactive notebook environment, which is convenient for us to write code and take notes at the same time. Basic environment The following is the basic environment of this article, do not detail the installation process. Ubuntu Ubuntu 18.04.5 LTS (Bionic Beaver) ubuntu-18.04.5-desktop-amd64.iso CUDA CUDA 11.2.2 cuda_11.2.2_460.32.03_linux.run cuDNN 8.1.1 libcudnn8_8.1.1.33-1+cuda11.2_amd64.deb libcudnn8-dev_8.1.1.33-1+cuda11.2_amd64.deb libcudnn8-samples_8.1.1.33-1+cuda11.2_amd64.deb Anaconda […]