Go環(huán)境的安裝

一、安裝

安裝包下載地址為

https://golang.org/dl/

https://golang.google.cn/dl/

https://studygolang.com/dl

1.在windows下

安裝完成后,配置環(huán)境變量:

GOROOT:Go語言的安裝路徑

GOPATH:Go語言的工作空間,不能與 GOROOT 相同(存放用戶自己的源碼文件)

Path: ;%GOROOT%\bin\ ; %GOPATH%\bin\

GoPath下應(yīng)該有三個文件夾:

src?:包含Go的源文件,它們被組織成包(每個目錄都對應(yīng)一個包)

pkg:包含包對象,也即編譯好的庫文件 *.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,運行即可

另一種(還沒運行)

@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位操作系統(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的時候

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

打開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,

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容