- 下载 Vs Code
- 下载 Go 环境
- 配置 go 环境变量
3.1 配置 GOROOT(Go安装路径in)
3.2 配置 GOPATH(Go工作区)
- 新建hello.go文件用vs code打开
- package main
- import (
- "fmt"
- )
- func main() {
- fmt.Println("Hello World!")
- }
复制代码 vscode会提示你安装go插件 点击 install all 会安装失败 (被墙了)
安装Go插件,就这一个就可以
安装Go语言开发工具包 ctrl+Shift+P
输入框中输入go:install 会自动搜索相关命令,选择Go:Install/Update Tools
- 安装失败解决办法:
- 在GOPATH的src目录下创建golang.org/x目录
- 在GOPATH/src/golang.org/x目录下
- 执行 git clone https://github.com/golang/tools.git tools命令
- 执行 git clone https://github.com/golang/lint.git 命令
- 按下Ctrl/Command+Shift+P再次执行 Go:Install/Update Tools 命令,在弹出的窗口全选并点击确定,这一次的安装都会SUCCESSED了
git clone https://github.com/golang/tools.git tools
go install github.com/ramya-rao-a/go-outline
go install github.com/acroca/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/rogpeppe/godef
go install github.com/sqs/goreturns
go install github.com/golang/lint/golint
go install github.com/cweill/gotests/gotests
go install github.com/ramya-rao-a/go-outline
go install github.com/acroca/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/rogpeppe/godef
go install github.com/sqs/goreturns
go install github.com/golang/lint/golint
go install github.com/cweill/gotests/gotests
- 安装失败解决办法 使用go mod 代理安装
- # Go 1.13 及以上(推荐)
- # Windows执行
- go env -w GO111MODULE=on
- go env -w GOPROXY=https://goproxy.io,direct
- # Windows PowerShell 执行
- $env:GO111MODULE = "on"
- $env:GOPROXY = "https://goproxy.cn"
- # macOS 或 Linux 执行
- export GO111MODULE=on
- export GOPROXY=https://goproxy.cn
- # 或者 macOS 或 Linux 执行
- echo "export GO111MODULE=on" >> ~/.profile
- echo "export GOPROXY=https://goproxy.cn" >> ~/.profile
- source ~/.profile
- // 手动安装
- go get -u -v github.com/mdempsky/gocode
- go get -u -v github.com/uudashr/gopkgs/v2/cmd/gopkgs
- go get -u -v github.com/ramya-rao-a/go-outline
- go get -u -v github.com/acroca/go-symbols
- go get -u -v golang.org/x/tools/cmd/guru
- go get -u -v golang.org/x/tools/cmd/gorename
- go get -u -v github.com/cweill/gotests/...
- go get -u -v github.com/fatih/gomodifytags
- go get -u -v github.com/josharian/impl
- go get -u -v github.com/davidrjenni/reftools/cmd/fillstruct
- go get -u -v github.com/haya14busa/goplay/cmd/goplay
- go get -u -v github.com/godoctor/godoctor
- go get -u -v github.com/go-delve/delve/cmd/dlv
- go get -u -v github.com/stamblerre/gocode
- go get -u -v github.com/rogpeppe/godef
- go get -u -v github.com/sqs/goreturns
- go get -u -v golang.org/x/lint/golint
复制代码 - 项目下执行:go mod init 项目名 生成 go.mod
- vscode配置go环境
文件–>首选项–>设置
- {
- "go.buildOnSave": true,
- "go.buildFlags": [],
- "go.buildTags": "",
- "go.lintOnSave": true,
- "go.formatOnSave": true,
- "go.gopath": "E:\gohmoe",
- "go.goroot": "C:\go"
- }
复制代码
执行:go run 文件名
或者设置F5 launch.json里添加
- {
- "version": "0.2.0",
- "configurations": [
- {
- "name": "LaunchGo",
- "type": "go",
- "request": "launch",
- "mode": "auto",
- "remotePath": "",
- "port": 5546,
- "host": "127.0.0.1",
- "program": "${fileDirname}",
- "env": {
- "GOPATH": "E:/GoCode",
- "GOROOT": "C:/Program Files/Go"
- },
- "args": [],
- //"showLog": true
- }
- ]
- }
复制代码 按 F5 Debug执行
- 安装 code runner 插件 执行按钮执 行代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |