複数のプロジェクトを開くようにワークスペースを設定します

vscode が go を使用する場合、gopath の下で実行されていないと、表示される場合があります

Error message "go: go.mod file not found in current directory or any parent directory; see 'go help modules'"

また

"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."

効果はありませんが、面倒くさそうです。

以前のバージョン (go 1、17 以前) では、setting.json追加できます

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

1.18以降のバージョンなら使えますgo work

ワークスペースのルートで実行

go work init
go work use [floder-name] 


たとえば、私のディレクトリは次のように構成されています。ただ走れ

go work use gin1  // Or go work use .\gin1\

ディレクトリの下に複数のフォルダーがある場合は、使用できます

go work use -r [floder-name] 

ディレクトリ内のすべてのフォルダをトラバースするには

おすすめ

転載: blog.csdn.net/majiayu000/article/details/128047281