VScode show me the error after I install the proxy in vscode

Viewed 36692
6 Answers

You probably have more than one go module in your workspace. If that is the case, you can change the go extension settings, in order to allow gopls to look for multiple modules in the workspace. Just add the following to your settings.json:

"gopls": {
    "experimentalWorkspaceModule": true,
}

You can read more about gopls configuration in the docs: https://github.com/golang/tools/blob/master/gopls/doc/settings.md

To solve this, follow below steps :

step 1 : Open Vscode, and then go to settings.

step 2 : In the search bar , type gopls

step 3 : Just below that you will find settings.json, click on that

step 4 : Paste the below code their "gopls": { "experimentalWorkspaceModule": true, }

step 5 : Save it and restart the Vscode, You are good to go now.

Go 1.18+

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:

$ tree /my/parent/dir
/my/parent/dir
├── project-one
│   ├── go.mod
│   ├── project-one.go
│   └── project-one_test.go
└── project-two
    ├── go.mod
    ├── project-two.go
    └── project-two_test.go

Create and populate the file by executing go work:

cd /my/parent/dir
go work init
go work use project-one
go work use project-two

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 (
    ./project-one
    ./project-two
)

I had this error because I had not created my modules inside a src directory. So I had:

$GOPATH
   -> bin
   -> pkg
   -> github.com
      -> Module
         -> go.mod

and that needed to be:

$GOPATH
   -> bin
   -> pkg
   -> src
       -> github.com
          -> Module
            -> go.mod

The setting has changed, now you need to use:

"gopls": {
    "build.experimentalWorkspaceModule": true,
}

This is working now...

"gopls": {
    "build.experimentalWorkspaceModule": true
}
Related