使用GoLand运行写好的代码报错,报错信息:
package gowiki is not in GOROOT (D:\Program Files\Go\src\gowiki)
Compilation finished with exit code 1
通过命令行进入项目目录执行go build
或go run
就可以成功。
说明:
GOROOT=D:\Program Files\Go
GOPATH=D:\go
项目路径:D:\go\src\gowiki
解决:
方法一:
进入项目目录执行go mod
,执行完会在该目录生成go.mod
文件。
go mod init example/hello
方法二:设置GO111MODULE=off
go env -w GO111MODULE=off
Go Modules
模块是Go管理依赖的方式。
go mod命令
Go mod provides access to operations on modules.
Note that support for modules is built into all the go commands,
not just 'go mod'. For example, day-to-day adding, removing, upgrading,
and downgrading of dependencies should be done using 'go get'.
See 'go help modules' for an overview of module functionality.
Usage:
go mod <command> [arguments]
The commands are:
download download modules to local cache
edit edit go.mod from tools or scripts
graph print module requirement graph
init initialize new module in current directory
tidy add missing and remove unused modules
vendor make vendored copy of dependencies
verify verify dependencies have expected content
why explain why packages or modules are needed
Use "go help mod <command>" for more information about a command.
网友评论