1 回复
更多关于Golang IDE环境配置指南的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html
在VS Code中配置Golang开发环境,需要安装Go扩展并正确设置工具链。以下是具体步骤:
-
安装Go扩展:
- 在VS Code扩展市场中搜索"Go",安装由Go Team at Google发布的官方扩展
-
配置工具链:
# 启用Go模块支持 go env -w GO111MODULE=on # 安装必要的工具 go install golang.org/x/tools/gopls[@latest](/user/latest) go install github.com/go-delve/delve/cmd/dlv[@latest](/user/latest) -
配置settings.json:
{ "go.useLanguageServer": true, "go.languageServerFlags": ["-remote=auto"], "go.formatTool": "goimports", "go.lintTool": "golangci-lint", "[go]": { "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.organizeImports": true } } } -
调试配置(launch.json):
{ "version": "0.2.0", "configurations": [ { "name": "Launch Package", "type": "go", "request": "launch", "mode": "auto", "program": "${fileDirname}" } ] } -
测试环境是否正常工作:
package main import "fmt" func main() { fmt.Println("VS Code Go环境配置成功") }
运行上述代码,如果控制台输出"VS Code Go环境配置成功",说明环境配置完成。扩展会自动提供代码补全、跳转定义、实时错误检查等功能。

