Parent+child golang repositories with VSCode

Hello Everyone
I have a repository that I I have split into a child package/library/repository and a parent repository. I have both in separate VSCode projects.

So when I update the child and want the parent to catchup , I currently:

  1. commit a new version of child
  2. sync (push) the commit
  3. copy the commit id
  4. switch to the parent VS Code editor
  5. use go get -u <githuburl>@<commitid>

This works (but is a bit of a pain). But more importantly sometimes my child commit doesn’t work so I have to bounce back and forth between parent and child committing new version of child until things are working again (creating spurious commits)…

What I would like to do is :

  1. save to child
  2. Run parent with local copy of child
  3. When it’s working - then do the child commit+push

N.B. I still need to run/build parent with the commit child to check deployment for other users. I might need another VSCode project just for this…that basically pulls from both latest commits…

Does anyone have a better approach that they have been using?

Thank you in advance - Andy

Hello there. You can do it in couple of ways. The one with just go.mod file, is to add replace into the file with the path to the local copy. But my preferred option is to use go.work instead. It allows you to develop packages which are part of other projects you have and test them locally, before pushing anything into git. Official docs can be found here.

1 Like

(eventually) that worked really well for me…

I had some tidy I had to do before it worked - in case this helps others …

  • the replace has to be after the module line and before the go version line, e.g. replace github.com/whatever/child => ../child
  • the child go.mod has to start module github.com/whatever/child
  • every import (in parent and child) also has to be of the form github.com/whatever/...

Hope this helps others…

Have you tried go work? In this case you won’t need to replace imports or change anything else in go.mod files. It will do everything for you.