Visual Studio Code搭建Go环境

文章目录

  • Visual Studio Code搭建Go环境
    • 1.安装go
    • 2.安装git
    • 3.安装gcc
    • 4.安装visual studio code(v1.28.2)

Visual Studio Code搭建Go环境

1.安装go

这里选择安装go 1.11版本
下载地址:https://studygolang.com/dl

安装过程就不想细说了,安装完会自动配置GOROOT环境变量。

GOROOT :Go语言的安装路径。
GOPATH :Go语言的工作空间,不能与 GOROOT 相同。
Path : %GOROOT%\bin\ 和 %GOPATH%\bin\

GOPATH 下应有三个目录:
src :包含Go的源文件,它们被组织成包(每个目录都对应一个包)
pkg:包含包对象,也即编译好的库文件 *.a
bin:包含可执行命令

查看go的环境变量使用go env
Visual Studio Code搭建Go环境_第1张图片

2.安装git

下载地址:https://git-scm.com/downloads
go get需要用到git工具下载源码

3.安装gcc

mingw下载地址:https://sourceforge.net/projects/mingw-w64/files/Junk/
解压后将bin目录添加到环境变量path中

mingw包解析:

  • x86_64表示64位,i686 表示32位
  • threads 在window下使用可以选择win32,如需跨平台就是用posix
  • dwarf、sjlj 的异常模型选择,推荐使用dwarf即所谓dw2,这个模型便于调试。不过出来的东西较sjlj的东西体量稍大些。

4.安装visual studio code(v1.28.2)

下载地址:https://code.visualstudio.com/

安装中文插件
Chinese (Simplified) Language Pack for Visual Studio Code

一下是安装完vscode时需要安装的插件,注意后面的名称

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

自行下载安装不要通过vscode,应为golang.org被和谐了。go get会自动编译安装文件到GOPATH/bin目录下。

新建一个批处理文件,运行以下内容:

mkdir  %GOPATH%\\src\\golang.org\\x
git clone https://github.com/golang/tools.git %GOPATH%\\src\\golang.org\\x\\tools

go get -v github.com/mdempsky/gocode
go get -v github.com/uudashr/gopkgs/cmd/gopkgs
go get -v github.com/ramya-rao-a/go-outline
go get -v github.com/acroca/go-symbols
go get -v golang.org/x/tools/cmd/guru
go get -v golang.org/x/tools/cmd/gorename
go get -v github.com/derekparker/delve/cmd/dlv
go get -v github.com/stamblerre/gocode
go get -v github.com/rogpeppe/godef
go get -v github.com/ianthehat/godef
go get -v github.com/sqs/goreturns
%go get -v github.com/golang/lint%
git clone https://github.com/golang/lint.git %GOPATH%\\src\\golang.org\\x\\lint

go build -o %GOPATH%\\bin\\gocode.exe github.com/mdempsky/gocode
%go build -o %GOPATH%\\bin\\gopkgs.exe github.com/uudashr/gopkgs/cmd/gopkgs%
%go build -o %GOPATH%\\bin\\go-outline.exe github.com/ramya-rao-a/go-outline%
%go build -o %GOPATH%\\bin\\go-symbols.exe github.com/acroca/go-symbols%
%go build -o %GOPATH%\\bin\\guru.exe golang.org/x/tools/cmd/guru%
%go build -o %GOPATH%\\bin\\gorename.exe golang.org/x/tools/cmd/gorename%
%go build -o %GOPATH%\\bin\\dlv.exe github.com/derekparker/delve/cmd/dlv%
go build -o %GOPATH%\\bin\\gocode-gomod.exe github.com/stamblerre/gocode
go build -o %GOPATH%\\bin\\godef.exe github.com/rogpeppe/godef
go build -o %GOPATH%\\bin\\godef-gomod.exe github.com/ianthehat/godef
%go build -o %GOPATH%\\bin\\goreturns.exe github.com/sqs/goreturns%
go build -o %GOPATH%\\bin\\golint.exe golang.org/x/lint/golint

pause

vscode的配置, 文件->首选项->设置

"go.buildOnSave": "workspace",
"go.lintOnSave": "package",
"go.vetOnSave": "package",
"go.buildTags": "",
"go.buildFlags": [],
"go.lintFlags": [],
"go.vetFlags": [],
"go.coverOnSave": false,
"go.useCodeSnippetsOnFunctionSuggest": true,
"go.formatTool": "goreturns",
"go.goroot": "D:\\MySoft\\Go",
"go.gopath": "D:\\MySoft\\Go\\gopath",
"go.gocodeAutoBuild": false,
"terminal.integrated.shell.windows": "C:\\windows\\System32\\cmd.exe",
"go.autocompleteUnimportedPackages": true,
"files.autoSave": "off",
"go.docsTool": "guru",
"go.gocodePackageLookupMode": "go",
"files.associations": {
    "*.tpl": "html"
},
"go.inferGopath": true,

setting.json vscode的配置文件
launch.json 调试
task.json 任务

你可能感兴趣的:(miscellaneous)