英文:
Best practice to work on two github go projects
问题
我正在处理两个基于GitHub的Go语言项目,其中一个项目依赖于另一个项目。
假设我有项目A(github.com/A),它依赖于项目B(github.com/B)。目前,我正在对项目B进行更改,推送代码,并在项目A中执行go get github.com/B
,以获取项目B的最新代码。
这个过程耗时且不太合理。我考虑过在GO_PATH位置更改项目B的文件,但是在GO_PATH下载的项目是只读的。
有没有更好的方法来解决这个问题?
英文:
I am working on two github based golang projects where one project is dependent on other.
Let say I have project A (github.com/A) depending on project B (github.com/B). So as of now, I am making changes to project B, pushing the code, and executing go get github.com/B
in project A, to fetch the latest code of project B.
This procedure is time consuming and also doesn't sound right to me. I have thought the changing files of project B at GO_PATH location, but seems downloaded projects at GO_PATH are read only.
Is there any better way to do this?
答案1
得分: 0
利用golang工作区
如果你的golang版本是1.18+,你可以利用工作区功能来提高开发体验。
让我们使用你的例子,假设我们有github.com/A
依赖于github.com/B
。
- 确保它们在同一个父文件夹中,假设该文件夹的名称为
workspace
。 - 在
workspace
中执行cd
命令,然后执行go mod init ./A && go work use ./B
。 - 在
workspace
中运行go run github.com/A
。
结果是,在你的本地开发环境中,你将始终使用本地版本的github.com/B
,因此无需进行远程同步。
如果你使用的是较早版本的go,我认为你最好编写一些脚本来自动化这个过程。
英文:
Leverage golang workspaces
If your golang version is 1.18+ you can leverage the workspaces feature in order to improve your development experience.
Let's use your examples, so we have github.com/A
which depends on github.com/B
.
- Make sure they are in the same parent folder and let's assume that the name of that folder is
workspace
cd
inworkspace
, thengo mod init ./A && go work use ./B
- In the
workspace
rungo run github.com/A
The result would be that in your local development environment you will use always your local version of github.com/B
, so no need for remote syncing.
If you are using previous version of go, I think your best bet is to do some scripting in order to automate this process
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论