1

Context: We are using a monolithic repository architecture. This means we have one big github repo with many projects, each project using its own tech stack for ui, node, go, etc.

> /home/workspace/
>        ./nodejs_project1
>        ./reactui_project2
>        ./reactnative_ui_project3
>        ./go_identity_service_project4
>        ./go_graphql_api_project5
>        ./go_common  (<--- how to share this with other go modules?)
> 
> /home/go (GOPATH) - only for 3rd party vendor downloads fro go-get
>       ./src
>       ./bin
>       ./pkg

In go_common we have common code used in all go projects such as logging, database connections, our schema/models as structs, etc. We are using Go 1.11 and declaring modules in go.mod. We also have this entire workspace and projects OUTSIDE our GOPATH. We do not want any vendor/3rd party downloaded modules inside our repo, similar to how we .gitignore node_modules in our node.js project. So go-get is downloading vendor modules to GOPATH src/pkg as expected and they are accessible to import to any go project.

However, we cannot get imports references go_common's module to work. We tried doing go build and go install in go_common, which created a binary in GOPATH/bin, but that didn't help actually make it reference-able. Is there a standard way to do this, especially now that Go 1.11 and vgo integrated is suppose to not rely on GOPATH and make module management easier... ??

bjm88
  • 690
  • 1
  • 8
  • 16
  • 1
    Does this help / solve your problem? [How to use a module that is outside of “GOPATH” in another module?](https://stackoverflow.com/questions/52328952/how-to-use-a-module-that-is-outside-of-gopath-in-another-module/52330233#52330233) – icza Sep 22 '18 at 05:38
  • I will test it tonight, but looks like it could be yes. Declaring local path the module is exactly what I was looking for I think, especially if relative and not related to GOPATH at all. This should be better documented perhaps as its very common pattern and other tools like maven handle it very simply. – bjm88 Sep 22 '18 at 12:49
  • So at first try it is giving a go.mod parse error on building, also not sure what I would use as version just v0.0.0 ?... module mycompany.com/product/identityservice require ( replace company.com/product/go_common v0.0.0 => ../go_common .... – bjm88 Sep 22 '18 at 12:58
  • Ok think it is working, the replace has to be totally outside the require () listing. Thank you! if you put answer I will upvote. – bjm88 Sep 22 '18 at 13:03
  • If the same solution works for you, I'll just mark it as duplicate. – icza Sep 22 '18 at 13:18

0 Answers0