我的文件夹结构看起来像这样..。(说我的git回购名是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 ------<------------<------------------<----------------|现在,我想在我的"newmodule“中使用"package1”中定义的函数
当我点击go get /directort1 1/module1 1/package1 1在"new_module“时,上面写着.
github.com/<repo>@upgrade found (v0.0.0-20211215055943-92e412ad4a12), but does not contain package github.com/<repo>/directory1/module1/package1发布于 2021-12-20 10:44:26
Go 1.18有一个关于Go工作区文件的建议,它可以简化这个任务。
同时,可以使用指令文件中的go.mod引用位于本地文件系统上的模块。
demorepo/directory1/module1/go.mod
module github.com/<repo>/directory1/module1demorepo/directory2/newmodule/go.mod
module github.com/<repo>/directory2/newmodule
replace github.com/<repo>/directory1/module1 => ../../directory1/module1现在您可以在import github.com/<repo>/directory1/module1/package1中正常使用newmodule,它将引用本地module1。
您可能不希望replace指令位于go.mod文件本身中,而是复制它(例如,go.mod.local ),并在构建项目时使用它:go build -modfile go.mod.local . (还可以将*.local添加到.gitignore中)。
发布于 2021-12-20 08:13:22
方法:
如果您想在module1中使用newModule,那么您应该为module1制作一个新的repo,将您的逻辑放在github中。请确保对库使用适当的version。
import作为一个library,它将工作。
还引用模块依赖的正式文档,并检查根级依赖。
https://stackoverflow.com/questions/70418534
复制相似问题