一、安装
安装包下载地址为
或
或
https://studygolang.com/dl
1.在windows下
安装完成后,配置环境变量:
GOROOT:Go语言的安装路径
GOPATH:Go语言的工作空间,不能与 GOROOT 相同(存放用户自己的源码文件)
Path: ;%GOROOT%\bin\ ; %GOPATH%\bin\
GoPath下应该有三个文件夹:
src :包含Go的源文件,它们被组织成包(每个目录都对应一个包)
pkg:包含包对象,也即编译好的库文件 *.a
bin:包含可执行命令
查看go的环境变量使用go env
2.在linux下
二、在gopath中增加bin文件(用于visual studio code)
新建文件,在文件中编写一下内容
mkdir %GOPATH%\\src\\golang.org\\xgit 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
改名为run.bat,运行即可
另一种(还没运行)
@echo off
echo 正在运行
echo 下载tools等工具
git clone https://github.com/golang/tools.git C:/Users/Administrator/go/src/golang.org/x/tools
git clone https://github.com/golang/lint C:/Users/Administrator/go/src/golang.org/x/lint
git clone https://github.com/golang/net C:/Users/Administrator/go/src/golang.org/x/net
git clone https://github.com/golang/text C:/Users/Administrator/go/src/golang.org/x/text
git clone https://github.com/golang/crypto C:/Users/Administrator/go/src/golang.org/x/crypto
git clone https://github.com/golang/sys C:/Users/Administrator/go/src/golang.org/x/sys
git clone https://github.com/ramya-rao-a/go-outline.git C:/Users/Administrator/go/src/github.com/ramya-rao-a/go-outline
git clone https://github.com/acroca/go-symbols.git C:/Users/Administrator/go/src/github.com/acroca/go-symbols
git clone https://github.com/rogpeppe/godef.git C:/Users/Administrator/go/src/github.com/rogpeppe/godef
git clone https://github.com/sqs/goreturns.git C:/Users/Administrator/go/src/github.com/sqs/goreturns
git clone https://github.com/cweill/gotests.git C:/Users/Administrator/go/src/github.com/cweill/gotests
git clone https://github.com/josharian/impl.git C:/Users/Administrator/go/src/github.com/josharian/impl
git clone https://github.com/golang/lint.git C:/Users/Administrator/go/src/github.com/golang/lint
git clone https://github.com/mdempsky/gocode.git C:/Users/Administrator/go/src/github.com/mdempsky/gocode
git clone https://github.com/uudashr/gopkgs.git C:/Users/Administrator/go/src/github.com/uudashr/gopkgs
git clone https://github.com/stamblerre/gocode.git C:/Users/Administrator/go/src/github.com/stamblerre/gocode
rem 64位操作系统用
REM git clone https://github.com/derekparker/delve.git C:/Users/Administrator/go/src/github.com/derekparker/
REM git clone https://github.com/go-delve/delve.git C:/Users/Administrator/go/src/github.com/go-delve
cd "C:/Users/Administrator/go"
go install github.com/ramya-rao-a/go-outline
go install golang.org/x/tools/cmd/guru
go install golang.org/x/tools/cmd/gorename
go install github.com/acroca/go-symbols
go install github.com/rogpeppe/godef
go install github.com/sqs/goreturns
go install github.com/cweill/gotests/gotests
go install github.com/josharian/impl
go install github.com/golang/lint/golint
go install github.com/mdempsky/gocode
go install github.com/uudashr/gopkgs/cmd/gopkgs
go build -o C:\\Users\\Administrator\\go\\bin\\gocode-gomod.exe github.com/stamblerre/gocode
echo 当模块设置成GO111MODULE=on的时候
go install golang.org/x/tools/cmd/goimports
rem 64位操作系统用
REM go install github.com/derekparker/delve/cmd/dlv
REM go get -v -u https://github.com/go-delve/delve/delve/cmd/dlv
@cmd.exe
pause
三、在visual studio code下配置
ctrl+shift+p搜索以下插件
go //go插件
Chinese (Simplified) Language Pack for Visual Studio Code //中文版
Code Runner
打开GOPATH文件夹:
ctrl+shift+p搜索settings.json
"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": "C:\\Go",
"go.gopath": "D:\\gopath",
"go.gocodeAutoBuild": false,
"terminal.integrated.shell.windows": "C:\\windows\\System32\\cmd.exe",
"go.autocompleteUnimportedPackages": true,
"go.docsTool": "guru",
"go.gocodePackageLookupMode": "go",
"files.associations": {
"*.tpl": "html"
},
"go.inferGopath": true,
有疑问加站长微信联系(非本文作者)