当前位置:网站首页>Go path customized project path package dependency
Go path customized project path package dependency
2022-06-24 16:37:00 【Constant constant】
go Our projects are basically go module Pattern , Fast and convenient package dependency and version management , But sometimes some old projects need maintenance , Is still go path Pattern , This old model may be chosen by some new scholars with a little knowledge go module, Old scholars may have long been forgotten , Record from this .
One 、 Introduction to global environment path
GOROOT=C:/go
1、goroot/src Next is go Own package .
2、go mod In mode ,gopath/pkg/mod/ If you can't find a package, it will be sent from root/src Path finding
3、go path In mode ,gopath/src/ Packages that don't exist in them will also come from root/src Path finding
GOPATH=E:/go
1、 No matter what go mod still gopath Pattern , This directory needs to have .
2、 if go mod Pattern , The third-party dependent packages will be in this directory ./pkg/mod Next , Here's the picture :
3、 if go path Pattern , The third-party dependent packages will be in this directory ./src Next , Here's the picture :
Two 、go path Project deployment under mode
go mod Your code can be placed anywhere , This is relative gopath A convenient place , No matter where the project code is , The dependent packages are all as mentioned above , All in gopath/pkg/mod Next , Is the absolute path containing .
but go path The general expression of ,gopath Project code , Need to put in gopath/src Under the table of contents , It's right gopth/src Relative inclusion of , Here comes a question , If I have two projects , There are lib My bag , If the code is lost in gopath/src Under the table of contents , The code is mixed up ?
Obviously there are solutions , as follows , I want to put the project in any directory E:/marketwork Next , Terminal execution git clone xxxx src, take git Code clone Down to the directory src Under the table of contents (src Don't create... Manually )
1、 Solve the package dependency problem of the project itself :
After that, you will find that there is a problem with the local package , Because all from the overall situation gopath/src To include , And your code is not gopath/src Next .
How to solve ? With golang For example , Set up the go path that will do , Here's the picture :
2、 solve github Package dependency problem :
After setting up , Local inclusion problem resolved , The project itself contains already green , Reopen ide Of terminal,run Find a third party github There is a problem with the dependent package of
This is the time , If you execute directly under this terminal go get github.com/xxxxxxx, You will find that the package is downloaded in the current directory , What's the problem ? There is no problem with this project , Because the picture above shows , Set the project's gopath, It is in the overall situation gopath and goroot Missing package , Finally, it will come to the project gopath Go find this bag .
But this will cause duplication and redundancy of package files , because github Bag on , Many projects could have been shared , There is no need to make a copy of each project's own directory . And down to the overall situation gopath/src Next , In the future, other projects will use , You can directly find , No more downloads , How to github From the package on to the global gopath/src Well ?
It's very simple , Open another terminal , The current terminal's gopath The environment change is set to global only , Again go get xxxx, It is downloaded to the global gopath/src Next , So in gopath In mode ,go get Where is the downloaded package , Depends on the current terminal settings go environment variable GOPATH What's your directory .
边栏推荐
- CDs view permission check
- Clickhouse high performance column storage core principle
- Go deep into the implementation principle of go language defer
- Finite element simulation in design
- Greenplum role-based fine-grained permission control
- 转置卷积详解
- Coding's first closed door meeting on financial technology exchange was successfully held
- MySQL timestamp format conversion date format string
- ThinkPHP vulnerability exploitation tool
- Istio FAQ: sidecar stop sequence
猜你喜欢

ZOJ - 4104 sequence in the pocket
![[go] concurrent programming channel](/img/6a/d62678467bbc6dfb6a50ae42bacc96.jpg)
[go] concurrent programming channel

B. Ternary Sequence(思维+贪心)Codeforces Round #665 (Div. 2)

Ps\ai and other design software pondering notes

Cognition and difference of service number, subscription number, applet and enterprise number (enterprise wechat)

Applet wxss
Advanced programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization

Applet - use of template
MySQL進階系列:鎖-InnoDB中鎖的情况
MySQL Advanced Series: Locks - Locks in InnoDB
随机推荐
50 growers | closed door meeting of marketing circle of friends ス gathering Magic City thinking collision to help enterprise marketing growth
A very good educational man and resource center planning scheme, with word file download
Leetcode notes of Google boss | necessary for school recruitment!
Global and Chinese market of computer protective film 2022-2028: Research Report on technology, participants, trends, market size and share
It may be a good idea to use simulation software in the cloud for simulation
How to open a futures account safely? Which futures companies are more reliable?
Recent progress of ffmpeg go
Global and Chinese market of inverted syrup 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL Advanced Series: Locks - Locks in InnoDB
Experience and suggestions on cloud development database
基于STM32的MD5校验
Transpose convolution learning notes
Serial of H3CNE experiment column - VLAN configuration experiment, access and trunk
A survey of training on graphs: taxonomy, methods, and Applications
The RTSP video structured intelligent analysis platform easynvr stops calling the PTZ interface through the onvif protocol to troubleshoot the pending status
Join in ABAP CDs
What is a framework?
Development trend of CAE simulation analysis software
Little red book, hovering on the edge of listing
The million bonus competition is about to start, and Ti-One will be upgraded to help you win the championship!