Hi.
I am currently faced with a problem that seems to be pretty unique. Hopefully someone will be able to help me out.
Essentially, I am trying to support two different projects A
and O
, both of which have been built on top of E
. There is a sizeable go library for E
, let’s call it lib-E
, but in order to support the other projects, they have released their own libraries, which are direct forks of lib-E
.
Notably, lib-A
and lib-O
do not have any import paths across the code base, and the go.mod
project definition is identical across all three libraries: github.com/maintainer/lib-E
. I assume this is done in order to minimise maintenance and allow for a more easy plug-and-play approach with consumers of the libs.
Maybe you’re already starting to see my issue now. Let’s assume I have two packages in my code base, one of them should be built against lib-A
, one against lib-O
. Both packages are identical in code, but as their underlaying dependency libs differ, so does the compiled output.
I have tried several approaches so far, all without luck:
-
Extracting both packages into their own repositories, along with their own
go.mod
, each containingreplace
statements oflib-E
to eitherlib-A
orlib-O
. This fails, since my maingo.mod
declares a direct dependency tolib-E
which will override the module replacements. -
Keeping the code in one repository, but using named imports in both packages (i.e.
import libA "github.com/maintainer/libE"), then using two replace directives in the main
go.modthat point to the individual repositories for
libAand
libO. This fails since both modules are still declared as
github.com/maintainer/libE`, so I end up with:
module declares its path as: github.com/maintainer/libE
but was required as: libA
As it stands now, I am starting to think that what I’m trying to do is impossible in Go, with the only solution being building two small binaries (each directly against libA
or libO
) and then use RPC between those small adapter binaries and my main application.
That’s obviously a lot of overhead I’d like to avoid if somehow possible. Can anyone think of a better solution for this problem?