I have a Go
project called Shop
. This project needs to have a web server
and a cli
tool.
Because of this, I created two different repositories, as they have their own dependencies. For example, the web server
uses fiber
framework, whereas the cli
tool uses cobra
package. Of course there are many other dependencies, that each project needs and they are not shared at all.
However, I have quite a bit of logic and types
that are the same in both projects (and therefore repositories).
About 15% of codebase in each repo is the same.
This means that at the moment I am copy/pasting the same code to the other repo whenever I change that shared functionality.
I want to simplify this somehow and I couldn't get a grip around how to do this properly.
Each repository lives outside of $GOPATH/src
. Is the solution to move them inside $GOPATH/src
and then use go get
to add let's say server
repository to cli
one?
CodePudding user response:
git submodules can be helpful, the doc.
CodePudding user response:
Something that might be helpful to share code in a common Go module: https://go.dev/doc/tutorial/call-module-code