My folder structure looks something like this... (say my git repo name is demorepo)
demorepo
|--directory1
|-- (no go.mod at this level)
|--module1
|--package1 --------->--------------->--------------------->----|
|--go.mod (github.com/demorepo/directory1/module1) |
|--go.sum |
|--module2 |
|--module3 |
|--directory2 |
|-- (no go.mod at this level) |
|--newmodule ------<------------<------------------<----------------|
Now, I want to use a function defined in "package1" in my "newmodule"
When I hit go get <repo_address>/directort1/module1/package1 at "new_module" it says ....
github.com/<repo>@upgrade found (v0.0.0-20211215055943-92e412ad4a12), but does not contain package github.com/<repo>/directory1/module1/package1
There is a proposal for a Go Workspace File for Go 1.18 which should simplify this task.
Meanwhile, you can use the
replacedirective in yourgo.modfile to refer to a module located on a local filesystem.demorepo/directory1/module1/go.mod:demorepo/directory2/newmodule/go.mod:Now you can
import github.com/<repo>/directory1/module1/package1innewmodulenormally and it'll refer to the localmodule1.You might not want the
replacedirective in thego.modfile itself, and instead make a copy of it e.g.go.local.modand use it when building your project:go build -modfile go.local.mod .(can also addgo.local.modto.gitignore).