Go项目: package project/name is not in GOROOT

从github上下载golang项目到本地运行go build编译,IDE上显示raycast.go: package raycast/engine is not in GOROOT (D:\Go\src\raycast\engine)错误

下面是项目结构:
项目结构
golang使用gopath或者gomod模式进行包管理,我使用gomod模式

export GO111MODULE=on

E:\raycastergo\目录下运行go mod init raycastergogo mod tidy命令。目录下会生成两个文件。就可以解决上面出现的raycast.go: package raycast/engine is not in GOROOT (D:\Go\src\raycast\engine)错误

go.mod
go.sum

注意:go mod init后面所跟的名称raycastergo必须与项目名称raycastergo一致

项目名称

否则会报错:

raycast.go: package raycast/engine is not in GOROOT (D:\Go\src\raycast/engine)
posted @ 2021-01-26 21:54  英格拉姆3号机  阅读(1935)  评论(0编辑  收藏  举报