git安裝
git官網:https://git-scm.com/
Downloads-->Windows-->64-bit Git for Windows Setup
下載後,雙擊安裝文件,正常安裝即可
go安裝
go官網:https://golang.google.cn/
Download go-->go1.12.13.windows-amd64.msi
下載後,雙擊安裝文件,正常安裝即可
此示例安裝目錄爲I:\install\Go
設置環境變量
GOROOT: I:\install\Go //go安裝目錄
GOPATH: I:\workspace\go\src\gopath //go項目工作目錄
Path: ;I:\install\Go\bin //追加在Path已有值後面即可
安裝工具包
由於網絡限制,go的很多工具都無法直接下載,因此在github上自定義一個gopath的倉庫
cd I:\workspace\go\src\
I: 回車
git clone --recursive https://github.com/DifficultWork/gopath.git
cd I:\workspace\go\src\gopath\src
go install github.com/nsf/gocode
go install github.com/uudashr/gopkgs/cmd/gopkgs
go install github.com/rogpeppe/godef
go install github.com/lukehoban/go-outline
go install github.com/newhook/go-symbols
go install golang.org/x/tools/cmd/guru
go install golang.org/x/tools/cmd/gorename
go install github.com/josharian/impl
go install github.com/sqs/goreturns
go install github.com/bytbox/golint
go install github.com/cweill/gotests/gotests
go install github.com/go-delve/delve/cmd/dlv
其他依賴工具包安裝
cd I:\workspace\go\src\gopath\/src/golang.org/x
git clone https://github.com/golang/sys.git
git clone https://github.com/golang/net.git
git clone https://github.com/golang/text.git
git clone https://github.com/golang/lint.git
git clone https://github.com/golang/tools.git
git clone https://github.com/golang/crypto.git
vscode安裝
vscode官網:https://code.visualstudio.com/
Download for windows
下載後正常安裝即可
安裝go插件
在點擊插件按鈕後,搜索中輸入go,第一個插件即是
配置go
設置-->擴展-->Go configuration->Edit in setting.json
{
"files.autoSave":"onFocusChange",
"go.buildOnSave": "workspace",
"go.lintOnSave": "package",
"go.vetOnSave": "package",
"go.buildFlags": [],
"go.lintFlags": [],
"go.vetFlags": [],
"go.useCodeSnippetsOnFunctionSuggest": false,
"go.formatTool": "goreturns",
"editor.fontSize": 18,
"go.goroot": "I:\\install\\Go",
"go.gopath": "I:\\workspace\\go\\src\\gopath"
}
ctrl+shift+p
輸入launch.json
{
// 使用 IntelliSense 瞭解相關屬性。
// 懸停以查看現有屬性的描述。
// 欲瞭解更多信息,請訪問: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"env": {},
"args": []
}
]
}
示例hello
目錄:I:\workspace\go\src\gopath\src\xiaofeng\hello\hello.go
f5即可運行
package main
import "fmt"
func main() {
fmt.Println("go hello for vscode ")
}
//output:
//go hello for vscode