在VSCODE中打开目录时,要解决错误,该目录由多个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 (https://github.com/golang/go/issues/32394),
and you can learn more here: https://github.com/golang/go/issues/36899.
从GO 1.18开始,对多模块工作区的本机支持。这是通过在您的父级目录中存在一个go.work文件来完成的。
对于目录结构,例如:
/parent
├── lesson-1
│ ├── go.mod
│ ├── hello-world.go
└── lesson-2
├── go.mod
├── slices.go
通过执行GO工作创建和填充文件:
cd parent
go work init
go work use lesson-1
go work use lesson-2
这将在您的父目录中添加一个go.work文件,其中包含您标记的用法的目录列表:
go 1.18
use (
./lesson-1
./lesson-2
)