DEV Community

chandra penugonda
chandra penugonda

Posted on

7 1

vscode: multiple Go Projects in a directory(Go 1.18+)

To fix error When opening a directory in VSCode that consists of multiple Go projects:

Error

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.
Enter fullscreen mode Exit fullscreen mode

From Go 1.18 onwards there is native support for multi-module workspaces. This is done by having a go.work file present in your parent directory.

For a directory structure such as:

/parent
├── lesson-1
│   ├── go.mod
│   ├── hello-world.go
└── lesson-2
    ├── go.mod
    ├── slices.go
Enter fullscreen mode Exit fullscreen mode

Create and populate the file by executing go work:

cd parent
go work init
go work use lesson-1
go work use lesson-2
Enter fullscreen mode Exit fullscreen mode

This will add a go.work file in your parent directory that contains a list of directories you marked for usage:

go 1.18

use (
    ./lesson-1
    ./lesson-2
)
Enter fullscreen mode Exit fullscreen mode

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay