一、配置GO环境变量

Windows:

GOROOT:go的bin目录上一级
Path:%GOROOT%/bin
GOPATH:项目的目录(安装插件时需要用到)

Mac:

vi ~/.bash_profile

添加如下文本:

export GOPATH=$HOME/goproject//$HOME指的是系统的~文件下

二、创建工作空间

1.在GOPATH目录下创建工作空间,即项目文件,如day01
在这里插入图片描述
2.新建项目main.go,编辑后保存
3.点击提示的Analysis Tools Missing
在这里插入图片描述
3.VSCode会自动加载GO的第三方类库,注意输出,因为有FQ的限制,基本上无法从golang.org上下载对应的类包。每个人的情况不一样,我的基本上都是安装失败,如下:
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 golang.org/x/tools/cmd/guru FAILED
Installing golang.org/x/tools/cmd/gorename FAILED
Installing github.com/go-delve/delve/cmd/dlv SUCCEEDED
Installing github.com/stamblerre/gocode FAILED
Installing github.com/rogpeppe/godef SUCCEEDED
Installing github.com/sqs/goreturns FAILED
Installing golang.org/x/lint/golint FAILED

三、手动安装插件

1.先在%GOPATH%/src/golang.org/x/tools(没有的话新建)下执行

git clone http://github.com/golang/tools

2.在%GOPATH%/src/github.com(没有的话新建)下执行:
(以下mdempsky、uudashr等文件夹不存的话均新建)

git clone https://github.com/mdempsky/gocode
git clone https://github.com/uudashr/gopkgs/cmd/gopkgs
git clone https://github.com/ramya-rao-a/go-outline
git clone https://github.com/acroca/go-symbols
git clone https://golang.org/x/tools/cmd/guru
git clone https://golang.org/x/tools/cmd/gorename
git clone https://github.com/go-delve/delve/cmd/dlv
git clone https://github.com/stamblerre/gocode
git clone https://github.com/rogpeppe/godef
git clone https://github.com/sqs/goreturns
git clone https://golang.org/x/lint/golint

3.之后在%GOPATH%下执行(目录与git clone时一致)

go install github.com/mdempsky/gocode
go install github.com/uudashr/gopkgs/cmd/gopkgs
go install github.com/ramya-rao-a/go-outline
go install github.com/acroca/go-symbols
go install github.com/go-delve/delve/cmd/dlv
go install golang.org/x/tools/cmd/guru //区别
go install golang.org/x/tools/cmd/gorename //区别
go install github.com/stamblerre/gocode
go install github.com/rogpeppe/godef
go install github.com/sqs/goreturns
go install golang.org/x/lint/golint //区别

4.第一步tools下载好后。
进入%GOPATH%\src\golang.org\x\tools\cmd\gorename目录,在此目录下,进入终端,执行go install,guru也执行同样操作。
5.因FQ问题,git clone https://golang.org/x/lint/golint,执行超时。
可从github上拉取代码,拷贝到%GOPATH%\src\golang.org\x\文件下。再执行go install golang.org/x/lint/golint。

git clone github.com/golang/lint/golint

6.总结:
VSCode无法自动安装情况下,手动安装的策略是先从github上拉取项目,再在本地install。注意安装时候要在%GOPATH%目录下,要在bin目录下生成对应的执行文件。