一验庙、安裝
安裝包下載地址為
或
或
https://studygolang.com/dl
1.在windows下
安裝完成后,配置環(huán)境變量:
GOROOT:Go語(yǔ)言的安裝路徑
GOPATH:Go語(yǔ)言的工作空間,不能與 GOROOT 相同(存放用戶自己的源碼文件)
Path: ;%GOROOT%\bin\ ; %GOPATH%\bin\
GoPath下應(yīng)該有三個(gè)文件夾:
src?:包含Go的源文件陌选,它們被組織成包(每個(gè)目錄都對(duì)應(yīng)一個(gè)包)
pkg:包含包對(duì)象剃根,也即編譯好的庫(kù)文件 *.a
bin:包含可執(zhí)行命令
查看go的環(huán)境變量使用go env
2.在linux下
二、在gopath中增加bin文件(用于visual studio code)
新建文件,在文件中編寫一下內(nèi)容
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,運(yùn)行即可
另一種(還沒(méi)運(yùn)行)
@echo?off
echo?正在運(yùn)行
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位操作系統(tǒng)用
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?當(dāng)模塊設(shè)置成GO111MODULE=on的時(shí)候
go?install?golang.org/x/tools/cmd/goimports
rem?64位操作系統(tǒng)用
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
打開(kāi)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,