vscode配置go语言开发环境

1、依赖包介绍

注意:

1. 以下所有关于gitclone和goinstall的操作都要在$GOPATH/src目录下完成。如果采用推荐的go get 方式获取则没有限制。

2. 系统环境为MacOS。

名称 介绍 描述 获取方式
go tools 工具类
包含guru、gorename等
https://github.com/golang/tools go get -u golang.org/x/tools/…
git clone https://github.com/golang/tools.git golang.org/x/tools
gopkgs 添加导入的包 https://github.com/uudashr/gopkgs go get -u github.com/uudashr/gopkgs/cmd/gopkgs
go-outline 一个实用的工具,用于提取go文件中的JSON声明 https://github.com/ramya-rao-a/go-outline go get -u github.com/ramya-rao-a/go-outline
go-symbols 用于提取go源文件树中的JSON声明 https://github.com/acroca/go-symbols go get -u github.com/newhook/go-symbols
gotests 为你的源代码生成Go测试 https://github.com/cweill/gotests go get -u github.com/cweill/gotests/…
gomodifytags 修改结构字段标签的工具
比如添加json标签
https://github.com/fatih/gomodifytags go get github.com/fatih/gomodifytags
impl 生成实现接口的方法 https://github.com/josharian/impl go get -u github.com/josharian/impl
fillstruct 用默认值填充结构文字 https://github.com/davidrjenni/reftools/tree/master/cmd/fillstruct go get -u github.com/davidrjenni/reftools/cmd/fillstruct
goplay Go Playground客户端 https://github.com/haya14busa/goplay go get -u github.com/haya14busa/goplay
godoctor Golang重构引擎 https://github.com/godoctor/godoctor git clone "https://github.com/godoctor/godoctor" github.com/godoctor/godoctor
dlv 为你的源代码生成Go测试 https://github.com/go-delve/delve go get -u github.com/go-delve/delve/cmd/dlv
MacOS
gocode 代码自动补全 https://github.com/mdempsky/gocode go get -u github.com/mdempsky/gocode
godef 跳转到定义 https://github.com/rogpeppe/godef git clone "https://github.com/rogpeppe/godef" github.com/rogpeppe/godef
goreturns 自动补全return语句中的零值 https://github.com/sqs/goreturf go get -u github.com/sqs/goreturn
golint 对在命令行中命名的Go源文件进行代码检测 https://github.com/golang/lint go get -u golang.org/x/lint/golint
gocode-gomod Go语言根据上下文自动补全的一个守护进程 https://github.com/stamblerre/gocod go get -u -v github.com/stamblerre/gocode

上面介绍了vscode中常见工具和依赖包的github地址以及基本的包获取方式
通常优先采取推荐方法:go get 获取包,这样不用执行手动克隆代码(git clone)和手动安装(go install)。对于那些无法通过go get方式获取的那就只能git clone -> go install了。

1、依赖包下载

如遇包下载失败优先尝试更改代理节点后重试
export GOPROXY=https://goproxy.io

image.png

否者只有按下列方式安装了
下面贴一个自己写的批量安装工具和依赖包的bash脚本,可以参考一下。自测通过。

#! /bin/bash

echo 查看当前go配置环境
go env

cd /Users/apple/go/src #进入你的GOPATH目录下的src文件夹下

#read -p "输入你的GOPATH路径: “ gopath
#cd $gopath/src/

echo "当前位置:” 
pwd

# 插件依赖工具
git clone https://github.com/golang/tools.git golang.org/x/tools
# 包含以下工具
# go get -u -v "golang.org/x/tools/cmd/guru”
# go get -u -v "golang.org/x/tools/cmd/gorename”


# 获取包的源码并编译 -v显示执行的命令(不用单独执行git clone + go install)
go get -u -v "github.com/go-delve/delve/cmd/dlv”
go get -u -v "github.com/uudashr/gopkgs/cmd/gopkgs”
go get -u -v "github.com/haya14busa/goplay”
go get -u -v "github.com/davidrjenni/reftools”
go get -u -v "github.com/stamblerre/gocode”


#下载依赖包到$GOPATH/src文件夹下的指定目录
# 克隆代码到指定路径下
git clone "https://github.com/golang/lint.git" golang.org/x/lint

git clone "https://github.com/mdempsky/gocode" github.com/mdempsky/gocode
git clone "https://github.com/ramya-rao-a/go-outline" github.com/ramya-rao-a/go-outline #go get 可以成功
git clone "https://github.com/acroca/go-symbols" github.com/acroca/go-symbols #go get 可以成功
git clone "https://github.com/cweill/gotests" github.com/cweill/gotests #go get 可以成功
git clone "https://github.com/fatih/gomodifytags" github.com/fatih/gomodifytags #go get 可以成功
git clone "https://github.com/josharian/impl" github.com/josharian/impl
git clone "https://github.com/godoctor/godoctor" github.com/godoctor/godoctor
git clone "https://github.com/rogpeppe/godef" github.com/rogpeppe/godef
git clone "https://github.com/sqs/goreturns" github.com/sqs/goreturns

# #执行go install
go install golang.org/x/lint

go install github.com/mdempsky/gocode
go install github.com/ramya-rao-a/go-outline
go install github.com/acroca/go-symbols
go install github.com/cweill/gotests/…
go install github.com/fatih/gomodifytags
go install github.com/josharian/impl
go install github.com/godoctor/godoctor
go install github.com/go-delve/delve/cmd/dlv
go install github.com/rogpeppe/godef
go install github.com/sqs/goreturns

#根据需要安装所需工具(可以到golang.org/x/tools文件夹里去查看有哪些工具)
go install golang.org/x/tools/cmd/guru
go install golang.org/x/tools/cmd/gorename

#注:优先使用go-get方法去获取工具包和依赖包,
# 如果无法获取,尝试到github使用git clone克隆对应的源代码到指定的目录,再使用go install进行安装

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,524评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,869评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,813评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,210评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,085评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,117评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,533评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,219评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,487评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,582评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,362评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,218评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,589评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,899评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,176评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,503评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,707评论 2 335