为了账号安全,请及时绑定邮箱和手机立即绑定

无法从 GO 中的不同文件导入包

无法从 GO 中的不同文件导入包

Go
倚天杖 2023-08-07 10:34:54
我正在使用go1.13.4,下面是我的项目结构:src/types/type.gosrc/utils/util.gogo.mod在 go.mod 中:module example.com/graphqlgo 1.13require github.com/graph-gophers/graphql-go v0.0.0-20191031232829-adde0d0f76a3在 src/types/type.go 中:package typestype USER struct {   ...}在 src/utils/util.go 中,package utilsimport (    "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-modulesgo.mod并且我已经在项目根目录的文件中设置了模块名称。
查看完整描述

1 回答

?
繁花如伊

TA贡献2012条经验 获得超12个赞

根据您当前的布局,导入路径typesexample.com/graphql/src/types

go.modsrc如果你有那个结构的话应该在里面。或者更好的办法是摆脱srcgo.mod必须位于typesutils文件夹旁边。


查看完整回答
反对 回复 2023-08-07
  • 1 回答
  • 0 关注
  • 64 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信