1

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?

  • Does this answer your question? [Always require the latest version of a dependency in go.mod](https://stackoverflow.com/questions/68273365/always-require-the-latest-version-of-a-dependency-in-go-mod) – Jay Nov 25 '22 at 11:24
  • 1
    You will have to automate it using a small script. I would suggest using makefile and add a command to go get the latest version of your dependency, so when you do say `make build` it gets updated each time before building. – Jay Nov 25 '22 at 11:26
  • @Jay Agreed, might need either `Makefile` or something like `Bazel`. – Divyanshu Juneja Nov 25 '22 at 12:40
  • There is a better way: the "replace" directive in go.mod, you would replace github.com/B to the path on the local filesystem of the checked out B. This obviously only during development. See https://github.com/golang/go/wiki/Modules#when-should-i-use-the-replace-directive – marco.m Nov 25 '22 at 14:47

1 Answers1

0

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

P. Danielski
  • 550
  • 7
  • 17