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

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

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

问题

我有以下的项目结构:

.
├── daos
│   ├── daos.go
│   ├── daos.iml
│   ├── go.mod
│   └── go.sum
├── entities
│   ├── entities
│   │   └── pets.go
│   ├── entities.iml
│   └── go.mod
└── pkg.iml

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

go: 找不到 github.com/goncharovmvdev/pets/entities/pets 包的模块
github.com/goncharovmvdev/pets/daos 导入
    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/>

.
├── daos
│&#160;&#160; ├── daos.go
│&#160;&#160; ├── daos.iml
│&#160;&#160; ├── go.mod
│&#160;&#160; └── go.sum
├── entities
│&#160;&#160; ├── entities
│&#160;&#160; │&#160;&#160; └── pets.go
│&#160;&#160; ├── entities.iml
│&#160;&#160; └── go.mod
└── pkg.iml

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

go: finding module for package github.com/goncharovmvdev/pets/entities/pets
github.com/goncharovmvdev/pets/daos imports
	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:

确定