简体   繁体   中英

Packaging a Go module with local Go module dependencies

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?

Based on what I can gather, Go doesn't support the importing of other modules locally unless you use replace and then include it twice, once in a subfolder and again in the vendor folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM