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:

  1. {
  2. "go.buildOnSave": true,
  3. "go.lintOnSave": true,
  4. "go.vetOnSave": true,
  5. "go.buildFlags": [],
  6. "go.lintFlags": [],
  7. "go.vetFlags": [],
  8. "go.coverOnSave": false,
  9. "go.useCodeSnippetsOnFunctionSuggest": false,
  10. "go.formatOnSave": true,
  11. //goimports
  12. "go.formatTool": "goreturns",
  13. "go.goroot": "",//你的Goroot
  14. "go.gopath": "",//你的Gopath
  15. }

接着安装依赖包支持(网络不稳定,请直接到 Github Golang 下载再移动到相关目录):

  1. go get -u -v github.com/nsf/gocode
  2. go get -u -v github.com/rogpeppe/godef
  3. go get -u -v github.com/zmb3/gogetdoc
  4. go get -u -v github.com/golang/lint/golint
  5. go get -u -v github.com/lukehoban/go-outline
  6. go get -u -v sourcegraph.com/sqs/goreturns
  7. go get -u -v golang.org/x/tools/cmd/gorename
  8. go get -u -v github.com/tpng/gopkgs
  9. go get -u -v github.com/newhook/go-symbols
  10. go get -u -v golang.org/x/tools/cmd/guru
  11. go get -u -v github.com/cweill/gotests/...

vscode 还有一项很强大的功能就是断点调试,结合 delve 可以很好的进行 Go 代码调试

  1. go get -v -u github.com/peterh/liner github.com/derekparker/delve/cmd/dlv
  2. brew install go-delve/delve/delve(mac可选)

如果有问题再来一遍:

  1. go get -v -u github.com/peterh/liner github.com/derekparker/delve/cmd/dlv

注意:修改”dlv-cert”证书, 选择”显示简介”->”信任”->”代码签名” 修改为: 始终信任

打开首选项-工作区设置,配置launch.json:

  1. {
  2. "version": "0.2.0",
  3. "configurations": [
  4. {
  5. "name": "main.go",
  6. "type": "go",
  7. "request": "launch",
  8. "mode": "debug",
  9. "remotePath": "",
  10. "port": 2345,
  11. "host": "127.0.0.1",
  12. "program": "${workspaceRoot}",//工作空间路径
  13. "env": {},
  14. "args": [],
  15. "showLog": true
  16. }
  17. ]
  18. }

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.

链接