When vscode uses go, if it is not running under gopath, it may appear
Error message "go: go.mod file not found in current directory or any parent directory; see 'go help modules'"
or
"Error loading workspace: You are outside of a module and outside of $GOPATH/src. If you are using modules, please
open your editor to a directory in your module. If you believe this warning is incorrect, please file an issue:
https://github.com/golang/go/issues/new."
It won't have any effect, but it looks annoying.
In earlier versions (go 1, 17 and earlier), you can setting.json
add
"gopls": {
"experimentalWorkspaceModule": true,
}
If it is a version after 1.18, you can usego work
At the root of the workspace run
go work init
go work use [floder-name]
For example, my directory is structured like this. just run
go work use gin1 // Or go work use .\gin1\
If there are multiple folders under the directory, you can use
go work use -r [floder-name]
To traverse all folders in the directory