我写了一个 main.go
程序并在代码的开头声明了包,但它标记为红色,如下所示:
当我将鼠标悬停在包裹上时,它会显示以下内容:
gopls requires a module at the root of your workspace.
You can work with multiple modules by opening each one as a workspace folder.
Improvements to this workflow will be coming soon, and you can learn more here:
https://github.com/golang/tools/blob/master/gopls/doc/workspace.md.
我需要有关如何传递此错误的帮助。非常感谢。
最佳答案
您需要运行命令 go mod init
从项目根目录的命令行。看起来你是从 go-microservice/prod-api
运行的,但它应该在你的 .git
所在的地方运行生活。如 prod-api
实际上是git项目的根目录,那么你需要在VSCode中打开那个文件夹而不是go-microservice
.
关于go - "package main"在 main.go 文件夹中标记为红色的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66146161/