最近入坑golang,由于已被ms大法洗脑首先想到了vscode。相信比别的教程能给您更快带入门(坑),O(∩_∩)O。
windows 配置也可参考以下过程,本人都装过大同小异。
1、安装vscode
安装就不多说了,附官网地址 https://code.visualstudio.com/Download,下载deb版。
2、安装golang环境
在Go语言中文网https://studygolang.com/dl,上就可以下载,386是32位,amd64是64位。
配置环境变量:在终端执行gedit ~/.bashrc,在文件尾部添加如下内容。注意配置GOBIN,windows下不用配置也没事,linux下忘了有啥问题了,总之配上就没错。运行 . ~/.bashrc 更新环境变量。
#Go environment,go_x64即go源码根目录
export PATH=$PATH:~/GoWorks/go_x64/bin
#第三方依赖路径
export GOPATH=~/GoWorks/thirdParty
#测试代码路径
export GOPATH=$GOPATH:~/GoWorks/testPath
终端执行 go env 能出打印信息证明配置成功。
3、安装vscode golang扩展插件
搜索go,安装插件。
4、安装golang扩展插件所需工具
按F1弹出command palette,选择GO:Install/Update Tools。
勾选所有工具,点击ok。
然后等。是的,在天朝是装不完所有的。有一部分工具会安装失败。扩展插件默认的下载地址golang.org是被墙的,哈哈哈!
先下载
1 https://github.com/golang/tools
2 https://github.com/golang/arch
3 https://github.com/golang/sys
下的源码到~/GoWorks/thirdParty/golang.org/x/路径下,大部分插件能直接安装成功。
福利!给你们附上所有工具的源码地址吧,手动git clone 再执行 go install 安装就行,各工具的功能在3中插件介绍中都有:
1 gocode https://github.com/mdempsky/gocode
2 gopkgs https://github.com/uudashr/gopkgs
3 go-outline https://github.com/ramya-rao-a/go-outline
4 go-symbols https://github.com/acroca/go-symbols
5 guru https://github.com/golang/tools
6 gorename https://github.com/golang/tools
7 dlv https://github.com/go-delve/delve
8 gocode-gomod https://github.com/stamblerre/gocode
9 godef https://github.com/rogpeppe/godef
10 goreturns https://github.com/sqs/goreturns
11 golint https://github.com/golang/lint
12 gotests https://github.com/cweill/gotests
13 gomodifytags https://github.com/fatih/gomodifytags
14 impl https://github.com/josharian/impl
15 fillstruct https://github.com/davidrjenni/reftools
16 goplay https://github.com/haya14busa/goplay
17 godoctor https://github.com/godoctor/godoctor
5、小试牛刀
在2中的testPath下创建如下文件路径。
创建main.go,用vscode打开按F5开撸吧!
package main
import "fmt"
func main() {
fmt.Println("Hello, World~~")
}