go语言开发,选择vscode作为IDE工具也是一个不错的选择,毕竟goland收费,老是破解也挺麻烦,处了这点,不过说实话挺好用的。vscode的话相对来说就毕竟原始,适合初学者。

1、vscode首先需要安装go语言插件,在vscode扩展中搜索“go”,如下图,下载安装go插件

2、vscode环境配置

 打开vscode设置,菜单File -> Preferences -> Settings,Extensions=>Go configuration找到GoPath设置项,选择Edit in setting.json

 设置GoPath(go工作路径)和GoRoot(go安装包路径)路径,如下图

3、vscode会自动弹框提示安装其他插件(编写go代码时),如下图,选择InstallAll

 不过由于网络限制问,基本是安装不成功

 解决办法,把安装失败信息拷贝出来,然后一个个手动下载到go工作目录src对应目录下

以github.com开头的,如下这些,在src目录下创建一个目录,命名为github

Installing github.com/mdempsky/gocode FAILED
Installing github.com/uudashr/gopkgs/cmd/gopkgs FAILED
Installing github.com/ramya-rao-a/go-outline FAILED
Installing github.com/acroca/go-symbols FAILED
Installing github.com/cweill/gotests/... FAILED
Installing github.com/fatih/gomodifytags FAILED
Installing github.com/josharian/impl FAILED
Installing github.com/davidrjenni/reftools/cmd/fillstruct FAILED
Installing github.com/haya14busa/goplay/cmd/goplay FAILED
Installing github.com/godoctor/godoctor FAILED
Installing github.com/go-delve/delve/cmd/dlv FAILED
Installing github.com/stamblerre/gocode FAILED
Installing github.com/rogpeppe/godef FAILED
Installing github.com/sqs/goreturns FAILED

在src/github目录下,git clone下载这安装失败的插件

git clone https://github.com/mdempsky/gocode
git clone https://github.com/uudashr/gopkgs
git clone https://github.com/ramya-rao-a/go-outline
git clone https://github.com/acroca/go-symbols
git clone https://github.com/cweill/gotests
git clone https://github.com/fatih/gomodifytags
git clone https://github.com/josharian/impl
git clone https://github.com/davidrjenni/reftools
git clone https://github.com/haya14busa/goplay
git clone https://github.com/godoctor/godoctor
git clone https://github.com/go-delve/delve
git clone https://github.com/stamblerre/gocode
git clone https://github.com/rogpeppe/godef
git clone https://github.com/sqs/goreturns

下载成功后,再在src目录下新建一个github.com目录,把上面下载的插件安按照按照失败提示信息放到相应目录下,注意路径一定要和前面提示的路径一致,

对应golang.org/x/开的插件,在src目录下新建目录golang.org\x,然后去github go官方地址https://github.com/golang,找到对应插件库下载下来即可,目前暂时要用到的只有tools和lint库,地址如下,以后开发中遇到“golang.org/x”库缺少的情况,都可以这样解决

git clone https://github.com/golang/tools.git
git clone https://github.com/golang/lint.git

下载下来后如下,

 在src目录下执行如下命令:

go install golang.org/x/tools/cmd/guru
go install golang.org/x/tools/cmd/gorename
go install golang.org/x/lint/golint

会在go工作目录bin下生成相应的可执行文件,如下图

01-13 02:53