主页 > 知识库 > Go 语言 IDE 中的 VSCode 配置使用教程

Go 语言 IDE 中的 VSCode 配置使用教程

热门标签:百度竞价排名 AI电销 服务外包 地方门户网站 铁路电话系统 呼叫中心市场需求 网站排名优化 Linux服务器

Gogland 是 JetBrains 公司推出的Go语言集成开发环境。Gogland 同样基于 IntelliJ 平台开发,支持 JetBrains 的插件体系。官方:https://www.jetbrains.com/go/。关于 Goland 相关配置参考该链接即可。Goland 用的好好的,为啥突然想用到 VSCode 呢 ?VSCode 是目前比较流行的 IDE 工具,在功能方面也相对齐全,使用方面也比较友好。不过对于 Golang 来说,配置起来不算太麻烦,只能说其中有一些比较坑的地方,今天我们也就是来填坑的(该死的天朝网络,要不然也不用这么费劲了)。

一、Golang 环境配置

关于 Goland 的系统环境配置,这里就不在过多讲解,可以直接参考该链接的前半部分即可。

二、安装配置 VSCode

下载链接:https://code.visualstudio.com/

选择自己系统对应的版本就可以,这个做 IT 的都不知道那就转行吧。

2.1 安装 golang 插件

进入Visual Studio Code,使用快捷键F1,打开命令面板

在上图光标处·输入 exten ,然后选择“Extensions:Install Extension”,如下图

查询并安装 Go 插件

提示:在插件列表中,选择 Go,进行安装,安装之后,系统会提示重启Visual Studio Code。由于我这里已经安装过了,所以不会出现 "Install" 选项。

2.2 开启自动保存功能

打开Visual Studio Code,找到菜单File -> Preferences -> Settings,如下图:

选中 "User Settings" 配置如下内容

{
 "files.autoSave": "onFocusChange",
 "editor.fontSize": 18,
 "go.goroot": "D:\\Go",
 "go.gopath": "D:\\Golang\\MyGO"
}

其他保持默认配置即可;

2.3 执行相关命令(自行安装好git)

更多详细信息参考:https://marketplace.visualstudio.com/items?itemName=ms-vscode.Go

1)安装gocode

打开命令提示符(以管理员身份打开),输入:

go get -u -v github.com/nsf/gocode

2)安装godef

go get -u -v github.com/rogpeppe/godef

3)安装golint

# 创建 $GOPATH/src/golang.org/x
cd $GOPATH/src/golang.org/x
git clone https://github.com/golang/tools.git
git clone https://github.com/golang/lint.git

# 完成以上步骤后,执行
go get golang.org/x/lint/golint

如果你遇到了类似如下错误,就可以通过 git clone 的方式把包下载到本地,再进行安装即可解决问题;

Fetching https://golang.org/x/tools/go/buildutil?go-get=1
https fetch failed: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
package golang.org/x/tools/go/buildutil: unrecognized import path "golang.org/x/tools/go/buildutil" (https fetch: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)

4)安装go-find-references

go get -u -v github.com/lukehoban/go-find-references

5)安装go-outline

go get -u -v github.com/lukehoban/go-outline

6)安装goreturns

go get -u -v sourcegraph.com/sqs/goreturns

7)安装gorename

go get -u -v golang.org/x/tools/cmd/gorename

提示:如果还提示报错,因为前面已经git clone 下来了,可以执行执行"go installgolang.org/x/tools/cmd/gorename";

8)安装gopkgs

go get -u -v github.com/tpng/gopkgs

9)安装go-symbols

go get -u -v github.com/newhook/go-symbols

2.4 写一个程序进行测试

可以看到能够进行相关提示。这里我们执行完整程序测试一下,程序是否正常。

总结

到此这篇关于Go 语言 IDE 中的 VSCode 配置使用教程的文章就介绍到这了,更多相关go语言ide vscode配置内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
  • 详解Vscode中使用Eslint终极配置大全
  • 在vscode中配置python环境过程解析
  • Visual Studio Code (vscode) 配置 C / C++ 环境的流程
  • vscode 配置 python3开发环境的方法
  • vscode中eslint插件的配置(prettier配置无效)
  • VScode+Java配置与使用的详细步骤
  • VSCode下好用的Python插件及配置
  • VSCode下配置python调试运行环境的方法
  • 如何使用VSCode愉快的写Python于调试配置步骤
  • VSCode配置react开发环境的步骤

标签:仙桃 衡水 黄山 湘潭 崇左 铜川 兰州 湖南

巨人网络通讯声明:本文标题《Go 语言 IDE 中的 VSCode 配置使用教程》,本文关键词  ;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 收缩
    • 微信客服
    • 微信二维码
    • 电话咨询

    • 400-1100-266