go - 无法从 GO 中的其他文件导入包
问题描述
我正在使用go1.13.4
,下面是我的项目结构:
src/types/type.go
src/utils/util.go
go.mod
在 go.mod 中:
module example.com/graphql
go 1.13
require github.com/graph-gophers/graphql-go v0.0.0-20191031232829-adde0d0f76a3
在 src/types/type.go 中:
package types
type USER struct {
...
}
在 src/utils/util.go 中,
package utils
import (
"example.com/graphql/types"
"fmt"
"io/ioutil"
"os"
)
构建项目时出现棕褐色错误:
$ go build ./...
src/utils/utils.go:4:2: cannot find module providing package example.com/graphql/types
我想知道为什么它找不到包裹example.com/graphql/types
?我正在阅读https://blog.golang.org/using-go-modulesgo.mod
并且我已经在项目根目录的文件中设置了模块名称。
解决方案
使用您当前的布局,导入路径types
为example.com/graphql/src/types
.
go.mod
src
如果你有那个结构,应该在里面。或者更好的是摆脱src
. go.mod
必须在types
andutils
文件夹旁边。
推荐阅读
- plot - 如何在 Mathematica 中找到两个 3D 曲面的交点?
- java - 你如何使用 Textureview 作为 cameraX 的预览 [Java]
- python - 将一个函数及其所有子函数传递给 njit
- java - 尝试通过 AutoConfigureMockMvc 自动配置时集成测试失败
- mysql - 需要将一列中的数据显示到标识符相同的单独行的同一列中
- nextflow - Google 生命科学中的 Nextflow 和抢占式机器
- deep-learning - 哪种格式更适合 tflite 模型 NCHW 或 NHWC?
- python - 在子列表中查找一个元素,当找到该元素时,将列表中的所有其他元素附加到另一个列表中
- c# - 针对 AD 组的 ASP.NET Core 5 MVC 上的 Windows 身份验证
- c++ - C++ 变量以及它们在内存中的存储位置(堆栈、堆、静态)