vscode在windows下golang开发环境搭建

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 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值