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 package to implement dependency Management in Go language

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Today, I will talk to you about how to use package to achieve dependency management in the Go language. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

Dependent syntax / * format: import xxx/xxx/package value Note the root directory is src*/// mode 1: import testting// mode 2: you can rely on multiple packages import ("testing") / / mode 3: you can also give package an individual name and call the package function import (t "testing") directly with an alias.

The package of go is similar to the class name in Java

Uppercase to indicate that it can be accessed by out-of-package code (not in a subdirectory of a root directory called outsourcing)

Src

-dirc1

-package name1

-dirc2

-package name2

If the first letter of the dirc1/package value is lowercase, the name1 cannot be referenced in the dirc2 directory

The package of the code can be inconsistent with the directory in which it is located

The package value is not necessarily related to the directory, but the package of the Go code in the same directory should be consistent.

Dependency management

Remote dependencies are obtained through go get, and go get-u forces remote dependencies to be updated from the network

Example: go get-u github.com/easierway/concurrent_map

If you want to put the code on GitHub, don't put the scr directory on GitHub, just start with the code path, without src

Vendor path

With the release of the 1.5 release version of Go, vendor directories have been added to solutions that rely on directory lookups in addition to GOPATH and GOROOT. Before Go1.6, you need to set environment variables manually

The solution for finding dependent package paths is as follows:

1, the vendor directory under the current package

2. Look in the superior directory until you find the vendor directory under src

3, look for dependency package 4. 0 under GOPATH. Look in the GOROOT directory

The problem of go dependency Management

1. In the same environment, different projects use different versions of the same package

2, cannot manage dependency on a specific version of the package (you cannot select a specific version)

After reading the above, do you have any further understanding of how to use package to implement dependency management in the Go language? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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

Internet Technology

Wechat

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

12
Report