Home  >  Article  >  Backend Development  >  Yes, it's better than nothing: Go dependency management tool dep

Yes, it's better than nothing: Go dependency management tool dep

Go语言进阶学习
Go语言进阶学习forward
2023-07-21 13:13:461400browse
<br>

Yes, it's better than nothing: Go dependency management tool dep

## “It takes about 3.4 minutes to read this article”

One of the issues criticized by many developers in the early days of Golang was the management of dependent packages. Before the release of Golang 1.5 release, this problem could only be solved by setting multiple GOPATHs. For example: both of my projects depended on Beego, but project A relied on

Beego1.1<span style="color: rgb(217, 72, 99);"></span>, Project B depends on Beego1.7<span style="color: rgb(217, 72, 99);"></span>, I have to set up two GOPATHs to distinguish them, and the GOPATHs also have to be switched when switching projects, which is extremely painful. Finally, Golang 1.5 release began to support dependency queries other than GOROOT and GOPATH, which is vender<span style="color: rgb(217, 72, 99);"></span>, so many big guys Let’s start making wheels. The better ones should be dep<span style="color: rgb(217, 72, 99);"></span> and glide <span style="color: rgb(217, 72, 99);">. </span>The protagonist appears

Today’s protagonist is

dep, Golang’s official Dependency tool, a tool used to manage and download project dependencies. The following is the official introductiondep is a prototype dependency management tool for Go. It requires Go 1.9 or newer to compile. dep is safe for production use.

install

    MacOS
  • brew install dep <span style="color: rgb(217, 72, 99);"></span>

  • Linux
  • curl https://raw.githubusercontent.com/golang/dep/master /install.sh | sh<span style="color: rgb(217, 72, 99);"></span>

    ##Windows
  • go get -u github.com /golang/dep/cmd/depWindows must compile it yourself, and confirm that

    $GOPATH/bin

    Add to environment variable $PATH<span style="color: rgb(217, 72, 99);"></span>

Verification

Enter <span style="color: rgb(217, 72, 99);">dep</span> on the command line and return car, the following prompt will appear, indicating that the installation has been successful.

Yes, it's better than nothing: Go dependency management tool dep

<br>

Features

1.dep init<br> Back up the current <span style="color: rgb(199, 37, 78);">vender</span> , create the <span style="color: rgb(61, 69, 76);">vender</span> directory and download all dependent packages in the project, generate <span style="color: rgb(199, 37, 78);">Gopkg.lock</span> and <span style="color: rgb(199, 37, 78);">Gopkg.toml</span>The following are two The function of the file is explained. Simply put, <span style="color: rgb(199, 37, 78);">Gopkg.toml</span> is the manifest file, Gopkg.lock# is the verification description file. Try not to modify it to avoid errors that may cause the two files to become out of sync.

A manifest - a file describing the current project's dependency requirements. In dep, this is the Gopkg.toml file.<br>A lock - a file containing a transitively-complete, reproducible description of the dependency graph. In dep, this is the Gopkg.lock file.

Yes, it's better than nothing: Go dependency management tool dep

<br>

2.dep status

Used to view the detailed information and status of project dependencies, very clear.

Yes, it's better than nothing: Go dependency management tool dep

#3.dep ensure# Try to ensure that all dependent libraries have been installed. If not, download them, which is equivalent to incrementally updating the dependent libraries. <br>

<br>

#4.dep ensure add github.com/RoaringBitmap/roaring@^1.0.1

Download and add new dependent libraries, and incrementally update the manifest file and verification description file. github.com/RoaringBitmap/roaring is the package name of the dependent library, 1.0.1 is the version number of the library.

Local cache

<span style="color: rgb(61, 69, 76);font-size: 16px;"> Of course</span><span style="font-size: 16px;color: rgb(199, 37, 78);">##dep<strong></strong></span> It will not be downloaded every time. Its working principle is the same as Mevan. It will search in the local warehouse first. If the local warehouse is not found, it will be downloaded on the network and added to the local warehouse. <span style="color: rgb(61, 69, 76);font-size: 16px;"></span>

$GOPATH/pkg/dep/sources

The above is the detailed content of Yes, it's better than nothing: Go dependency management tool dep. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:Go语言进阶学习. If there is any infringement, please contact admin@php.cn delete