Home  >  Article  >  Backend Development  >  Best practices for working with two github go projects

Best practices for working with two github go projects

王林
王林forward
2024-02-08 23:48:31703browse

处理两个 github go 项目的最佳实践

php editor Baicao brings you an introduction to the best practices for handling two GitHub Go projects. During the development process, we often need to deal with dependencies and code collaboration between multiple projects. This article will share some effective methods and suggestions to help you optimize the project structure, manage dependencies, resolve conflicts, and improve the maintainability and scalability of the code. Both beginners and experienced developers can benefit from it and improve development efficiency and project quality. Let’s explore these best practices together!

Question content

I am developing two golang projects based on github, one of which depends on the other.

Suppose I have project A (github.com/A), which depends on project B (github.com/B). So now I'm making modifications to project B, pushing the code, and executing go get github.com/B in project A to get the latest code for project B.

This process is very time consuming and doesn't sound right to me. I thought the GO_PATH location of project B's changed files, but it seems the GO_PATH downloaded project is read-only.

Is there a better way to do this?

Solution

Use golang workspace

If your golang version is 1.18, you can take advantage of the workspace feature to improve your development experience.

Let's use your example so we have github.com/A, which depends on github.com/B.

  1. Make sure they are in the same parent folder, assuming the folder is named workspace
  2. cd In workspace, then go mod init ./A && go work use ./B
  3. Run in workspace go run github.com/A

The result is that in your local development environment you will always use the local version of github.com/B, so there is no need to synchronize remotely.

If you are using a previous version of go, I think your best option is to write some scripts to automate this process

The above is the detailed content of Best practices for working with two github go projects. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete