将项目中的一个模块导入到同一项目中的另一个模块中。

huangapple go评论107阅读模式
英文:

Import go module in project to another module in the same project

问题

我有以下的项目结构:

  1. .
  2. ├── daos
  3. ├── daos.go
  4. ├── daos.iml
  5. ├── go.mod
  6. └── go.sum
  7. ├── entities
  8. ├── entities
  9. └── pets.go
  10. ├── entities.iml
  11. └── go.mod
  12. └── pkg.iml

我想将模块entities导入到daos中,但是出现了以下错误:

  1. go: 找不到 github.com/goncharovmvdev/pets/entities/pets 包的模块
  2. github.com/goncharovmvdev/pets/daos 导入
  3. github.com/goncharovmvdev/pets/entities/pets: 找到模块 github.com/goncharovmvdev/pets@latest (v0.0.0-20220625073141-e49db91a04de),但不包含包 github.com/goncharovmvdev/pets/entities/pets
英文:

I have the following project structure:
<br/>

  1. .
  2. ├── daos
  3. │&#160;&#160; ├── daos.go
  4. │&#160;&#160; ├── daos.iml
  5. │&#160;&#160; ├── go.mod
  6. │&#160;&#160; └── go.sum
  7. ├── entities
  8. │&#160;&#160; ├── entities
  9. │&#160;&#160; │&#160;&#160; └── pets.go
  10. │&#160;&#160; ├── entities.iml
  11. │&#160;&#160; └── go.mod
  12. └── pkg.iml

I want to import module entities to daos, but get the following error:

  1. go: finding module for package github.com/goncharovmvdev/pets/entities/pets
  2. github.com/goncharovmvdev/pets/daos imports
  3. github.com/goncharovmvdev/pets/entities/pets: module github.com/goncharovmvdev/pets@latest found (v0.0.0-20220625073141-e49db91a04de), but does not contain package github.com/goncharovmvdev/pets/entities/pets

答案1

得分: 1

如果你想将实体导入到daos中,有两种方法:

  1. 将实体的源代码推送到你的Github上。
  2. 你可以使用类似这样的替换指令(https://go.dev/doc/tutorial/call-module-code)。
英文:

If you want to import the entities to daos, there are 2 ways:

  1. Push the entities' source code to your Github.
  2. You can use the replace directive like this (https://go.dev/doc/tutorial/call-module-code)

huangapple
  • 本文由 发表于 2022年6月25日 16:31:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/72752392.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定