Home > Software engineering >  Packaging a Go module with local Go module dependencies
Packaging a Go module with local Go module dependencies

Time:01-21

If you have a module that has another module as a dependency, but that 2nd module isn't in a repo, how do you package/distribute the 1st module?

From what I understand, you have 2 options:

  1. Use the replace directive in go.mod to point to a local folder and then vendor the 2nd module.
  2. Keep it outside the vendor folder and rewrite all the import statements of the packages in the 2nd module so they are now packages of the main module.

Obviously the 1st option is the only reasonable one, but if so:

  1. Doesn't that mean the 2nd module is in 2 places, the original folder and the vendor folder?
  2. If not, how do you remove it from one of the folders? Removing either one seems to break things.
  3. Does Go simply not support offline/local module dependencies?

CodePudding user response:

Seems like you can import another module just fine using replace and pointing to a subfolder without needing to rename imports or vendor it. I was just getting errors from the editor/language server because it doesn't support nested modules (gopls), but everything seems to compile and run as expected.

  •  Tags:  
  • Related