无法从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"
)

构建项目时出现tan错误:

$ 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文件中设置了模块名称。

tsghj 回答:无法从GO中的其他文件导入包

在当前布局下,types的导入路径为example.com/graphql/src/types

如果您具有

go.mod结构,则它应位于src内部。或更好的办法是摆脱srcgo.mod必须位于typesutils文件夹旁边。

本文链接:https://www.f2er.com/3110549.html

大家都在问