当前位置:网站首页>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 .
边栏推荐
- 山金期货安全么?期货开户都是哪些流程?期货手续费怎么降低?
- How to use the national standard streaming media server to view the video stream of the surveillance camera? How to correctly use UDP and TCP protocols?
- Global and Chinese market of computer protective film 2022-2028: Research Report on technology, participants, trends, market size and share
- The RTSP video structured intelligent analysis platform easynvr stops calling the PTZ interface through the onvif protocol to troubleshoot the pending status
- Heavy release! Tencent cloud ASW workflow, visual orchestration cloud service
- A troubleshooting of golang memory leak
- [tke] troubleshooting tips for container problems
- Mathematics in machine learning -- point estimation (IV): maximum posteriori probability (map)
- Customized Tile Map cut - based on Tencent map
- proxy pattern
猜你喜欢

There are potential safety hazards Land Rover recalls some hybrid vehicles

A survey on dynamic neural networks for natural language processing, University of California

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

B. Terry sequence (thinking + greed) codeforces round 665 (Div. 2)
MySQL進階系列:鎖-InnoDB中鎖的情况
![[go] concurrent programming channel](/img/6a/d62678467bbc6dfb6a50ae42bacc96.jpg)
[go] concurrent programming channel

Ui- first lesson

C. Three displays codeforces round 485 (Div. 2)

Ps\ai and other design software pondering notes
Advanced programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization
随机推荐
Memo list: useful commands for ffmpeg command line tools
MySQL進階系列:鎖-InnoDB中鎖的情况
Global and Chinese market of insect proof clothing 2022-2028: Research Report on technology, participants, trends, market size and share
Factory mode
Handling of communication failure between kuberbetes pod
It may be a good idea to use simulation software in the cloud for simulation
One Minute! No code! Add [statistical analysis] to the website
[tke] modify the cluster corendns service address
SQL multi table updating data is very slow
Detailed explanation of transpose convolution in pytorch
What is browser fingerprint recognition?
Enterprise service growth path (7): what key factors will affect SaaS' sales performance?
What is the difference between get and post? After reading it, you won't be confused and forced, and you won't have to fight with your friends anymore
AI video structured intelligent security platform easycvr realizes intelligent security monitoring scheme for procuratorate building
Inter thread communication of embedded development foundation
AI video structured intelligent security platform easycvr intelligent security monitoring scheme for protecting community residents
C. K-th Not Divisible by n(数学+思维) Codeforces Round #640 (Div. 4)
Clickhouse high performance column storage core principle
PyTorch中的转置卷积详解
The mystery of redis data migration capacity