Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use godep in golang development

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use godep in golang development", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "how to use godep in golang development"!

introduced

Godep is a management tool to solve package dependencies. At present, the most mainstream one is to scan and record version control information, and shell before the go command to manage dependencies.

godep recommended for golang 1.6 onwards

Godep depends on vendor

Please manage the vendor.

installation

https://github.com/tools/godep

go get -u -v github.com/tools/godep

After successful installation, there will be a godep executable binary file under the bin directory of $GOPATH. The commands executed later are all using this. It is recommended that this directory be added to the global environment variable.

Package management using godep

The following commands are run from the root directory of the project

Pull dependency restore for developing godep restore

It is recommended that the development process use this command to synchronize dependency libraries

If the downloaded project contains only Godeps.json file and does not contain the third library, you can use godep restore command to download all dependent libraries to $GOPATH\src for development.

When godep restore is executed, godep will follow the list in Godeps/Godeps.json and execute go get -d -v in turn to download the corresponding dependency package to GOPATH.

If the save path (relative path under GOPATH) of an original dependency package is inconsistent with the download url path, for example, kubernetes on github path is github.com/kubernetes, and import code is my.io, it will cause failure to download successfully, that is, godep restore is unsuccessful. This can only be done manually, such as manually creating the $GOPATH/my.io directory and then git clone

detect dependency savecodep save

Automatically scans all external dependent libraries (non-system libraries) imported in the package to which the current directory belongs

Download all dependencies into the current project, creating the file Godeps\Godeps.json

Generate module dependency directory vendor`folder without Godeps` file

If development relies on using a three-party library and needs to be fixed with a certain version, please submit the Godeps`and vendor` folders completely.

Godeps/_workspace is generated by a lower version of godep. Upgrade is recommended.

There are two factors that make godep save successful:

The current package or package to be scanned can be compiled successfully: therefore, all dependent packages should have been saved in the current GOPATH path by either go get or manual operation.

Dependency packages must use a code management tool (e.g. git, hg): this is because godep needs to record revisions

This command is used to compile build, three-party build tools require additional configuration build parameters

godep compile run build

After the project is managed with godep, it is obviously impossible to compile and run the project with go run and go build.

Because the go command is directly to the GOPATH directory to find third-party libraries, and after 1.6 support vendor compilation, and use godep to download dependent libraries into Godeps/workspace directory, but does not affect the continued use of dependent GOPATH directory, so it does not conflict with the third-party tools themselves.

is used as the PRC

godep go build XXX

The go command in godp adds a layer of shell to the original go command. When godp goes, the workspace directory of the current project will be added to the GOPATH variable.

The role of the Godeps directory

When godep saves, godep copies all dependent package code from GOPATH path to Godeps directory and removes code management directory. This use is mainly to support a series of operations of godep go tool, especially after git clone has come down the code base, it is usually compiled directly with godep go install xxx, which can alleviate the troubles caused by golang's strict code path and package management to a certain extent.

When using IDE, you can add vendor to GOPATH to achieve code jumping and compilation functions, which is more convenient.

godep Other commands save list and copy dependencies into Godeps go run the go tool with saved dependencies get download and install packages with specified dependencies path print GOPATH for dependency code restore check out listed dependency versions in GOPATH update update selected packages or the go version diff shows the diff between current and previously saved set of dependencies version show version info At this point, I believe everyone has a deeper understanding of "how to use godep in golang development", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report