IDE
关于IDE每个人的喜好都不同,你可以使用较为独立的开发环境LiteIDE,也可以是VS或者Eclipse,甚至是notepad++,当然更不用说vim和emacs了。在这里,一种我比较喜欢的IDE:LiteIDE。
LiteIDE
LiteIDE算是集成的非常好Go IDE了,编译,调试,代码补全,功能可谓应有尽有。而且免费,开源,基于QT所以还跨平台。其安装异常简单,从官网上下载对应平台的安装包,然后解压到指定目录即可。如果无法访问,可以去镜像下载。
Gogland
Software development company JetBrains released another reliable IDE, but this time, for Golang. Gogland is a commercial IDE that provides a robust ergonomic environment for Go developers. It also features coding assistance, a debugger, and an integrated terminal.
Because an established company created Gogland, it has an extensive IntelliJ plugin ecosystem where you can get additional tools, should you need more.
Visual Studio Code
Created by Microsoft, Visual Studio Code is a full-featured, open-source IDE and code editor that supports a wide variety of programming languages. It features smart completion with IntelliSense; debugging using breakpoints, call stacks, and an interactive console; built-in Git integration; and a hierarchical folder and file explorer.
As another popular IDE, Visual Studio Code has a supportive community of Go developers that regularly contribute. With Visual Studio Code, you can extend functionalities with the array of available plugins.
vscode是微软基于Electron和web技术构建的开源编辑器, 是一款很强大的编辑器。开源地址:https://github.com/Microsoft/vscode
1、安装Visual Studio Code 最新版
官方网站:https://code.visualstudio.com/
下载Visual Studio Code 最新版,安装过程略。
2、安装Go插件
点击右边的 Extensions 图标
搜索Go插件
在插件列表中,选择 Go,进行安装,安装之后,系统会提示重启 Visual Studio Code。
建议把自动保存功能开启。开启方法为:选择菜单 File,点击 Auto save。
vscode代码设置可用于Go扩展。这些都可以在用户的喜好来设置或工作区设置(.vscode/settings.json)。
打开首选项-用户设置 settings.json:
{
"go.buildOnSave": true,
"go.lintOnSave": true,
"go.vetOnSave": true,
"go.buildFlags": [],
"go.lintFlags": [],
"go.vetFlags": [],
"go.coverOnSave": false,
"go.useCodeSnippetsOnFunctionSuggest": false,
"go.formatOnSave": true,
//goimports
"go.formatTool": "goreturns",
"go.goroot": "",//你的Goroot
"go.gopath": "",//你的Gopath
}
接着安装依赖包支持(网络不稳定,请直接到 Github Golang 下载再移动到相关目录):
go get -u -v github.com/nsf/gocode
go get -u -v github.com/rogpeppe/godef
go get -u -v github.com/zmb3/gogetdoc
go get -u -v github.com/golang/lint/golint
go get -u -v github.com/lukehoban/go-outline
go get -u -v sourcegraph.com/sqs/goreturns
go get -u -v golang.org/x/tools/cmd/gorename
go get -u -v github.com/tpng/gopkgs
go get -u -v github.com/newhook/go-symbols
go get -u -v golang.org/x/tools/cmd/guru
go get -u -v github.com/cweill/gotests/...
vscode 还有一项很强大的功能就是断点调试,结合 delve 可以很好的进行 Go 代码调试
go get -v -u github.com/peterh/liner github.com/derekparker/delve/cmd/dlv
brew install go-delve/delve/delve(mac可选)
如果有问题再来一遍:
go get -v -u github.com/peterh/liner github.com/derekparker/delve/cmd/dlv
注意:修改”dlv-cert”证书, 选择”显示简介”->”信任”->”代码签名” 修改为: 始终信任
打开首选项-工作区设置,配置launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "main.go",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}",//工作空间路径
"env": {},
"args": [],
"showLog": true
}
]
}
Wide
Wide is a web-based IDE for Golang programmers. It’s designed for collaborative development and works best for teams and web development agencies. Wide features include code highlight, debugging, Git integration, and more.
Because Wide is created and maintained by a Chinese developer, most of its documentation and support are in Chinese.
Atom With Go-Plus Plugin
If you’re already using Atom, your code editing experience in Golang can be improved with an open-source package called go-plus. With go-plus, you get instant, real-time feedback on your syntax and build errors.
The go-plus package offers almost all Golang support in Atom. It can also be used for tools, build flows, linters, vet, and coverage tools.
Go-plus also includes various code snippets and features such as autocomplete with gocode, code formatting with gofmt, goreturns, or goimports, and more.
Eclipse With GoClipse
Because Eclipse is a widely popular IDE, numerous plugins have been created for it. GoClipse is an Eclipse plugin for Golang that offers Go source code editing with configurable syntax highlighting and automatic indentation and brace completion.
GoClipse also serves as a project wizard and builder that reports syntax and build errors instantly. Additional features of GoClipse include debugging functionality and code assist.