從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 raycastergo
與go 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)