Best practice to work on two github go projects

huangapple go评论75阅读模式
英文:

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

  1. 确保它们在同一个父文件夹中,假设该文件夹的名称为workspace
  2. workspace中执行cd命令,然后执行go mod init ./A && go work use ./B
  3. 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.

  1. Make sure they are in the same parent folder and let's assume that the name of that folder is workspace
  2. cd in workspace, then go mod init ./A && go work use ./B
  3. In the workspace run go 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

huangapple
  • 本文由 发表于 2022年11月25日 19:22:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/74572061.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定