无法从 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-modules,并且我已经在项目根目录go.mod文件中设置了模块名称。

使用当前布局,types的导入路径example.com/graphql/src/types

如果你有这种结构,go.mod应该在src里面。或者更好的是摆脱src.go.mod必须位于"types"和"utils"文件夹旁边。

最新更新