golang development environment
原文链接 https://kasperdeng.github.io/go-dev-env/
注:以下为加速网络访问所做的原文缓存,经过重新格式化,可能存在格式方面的问题,或偶有遗漏信息,请以原文为准。
Installation
- Download go
- Go Complier:
- offcial: gc
- GNU GC: gccgo
- Go supports 3 instruction sets
- amd64 (a.k.a.
x86-64
); 6g,6l(Plan9 gc),6c,6a // support x84-64, naming as amd64 is to amd's contribution of inventing 64bit instruction set - 386 (a.k.a.
x86
orx86-32
); 8g,8l,8c(Plan9 gc),8a - arm (a.k.a. ARM); 5g,5l,5c(Plan9 gc),5a
- amd64 (a.k.a.
- Set Env Variables
- GOBIN: C:\Go\bin (optional, if no GOBIN, GOPATH will be used)
- GOARCH: x86-32bit: 386, x86-64bit: amd64, ARM: amr (android)
- GOOS: windows
- GOROOT: C:\Go
- GOPATH: C:\GOPATH
- To specify directories outside of $GOROOT that contain the source for Go projects and their binaries.
- Add to PATH: %GOBIN%
- Multi-Version GO Env
- GVM
- an interface to manage Go versions, like NVM(Nodejs Version Manager), RVM (Ruby Version Manager)
- Reference in astaxie/build-web-application-with-golang
Tools
IDE
Sublime
- Install package control
- "ctrl + `" or Menu: View -> Show console: input
import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf), 'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())
Restart sublime
- Install GoSublime
- ctrl+shift+p -> input install -> input GoSublime
- preferences —> package setting —> gosublime —> setting default, update env
- Restart sublime
{
"env": {
"path":"C:\\Go\\bin",
"GOROOT":"C:\\Go",
"GOPATH":"C:\\GOPATH",
"GOARCH":"amd64",
"GOOS":"windows",
"PATH":"%GOBIN%;%PATH%"
},
"comp_lint_enabled": true,
"comp_lint_commands": [
{"cmd": ["go", "install"]}
],
"on_save": [
{"cmd":"gs_comp_lint"}
]
}
ctrl+p -> gosublime
: to find related gosublime functions and key binding- keybinds: ctrl+.,ctrl+g: definition
- Build
- ctrl+b (cli console in sublime), then run the go commands
gosublime drawback: read code with goto definition but no easy way to go back.
Ref:
- http://www.v-lover.com/2014/12/24/go-built-environment/
- Godef for Sublime (currently not support windows)
Atom
- Lots of golang package support
- go-plus (but currently failed to install in my workspace)
Vim
- vim-go
- PluginInstall: Vundle: Plugin 'fatih/vim-go'
- GoInstallBinaries (need install Mercurial and add C:\Program Files\Mercurial\ to PATH)
- Install ctags: e.g. In Ubuntu, sudo apt-get install ctags and in /usr/bin/ctags
- Config the ctags path for tagbar: let g:tagbar_ctags_bin = '/usr/bin/ctags' (Ubuntu)
- Add key mapping to .vimrc, e.g.
au FileType go nmap gdf <plug>(go-def)
- Vim build-in
<C-o>
and<C-i>
help back/forward of code definition naviation <C-x><C-o>
auto go code complete by omnicomplete system,<C-n>
to select.- Add config to vimrc to support invoke gocode for code completion
" Golang
au BufNewFile,BufRead *.go setf go
autocmd FileType go setlocal omnifunc=go#complete#Complete
- If no config, use the gvim-ex which support it by default (unknown why)
autocompletion is dependent on the
gocode
, when golang upgrade, please upgrade the gocode bygo get -u github.com/nsf/gocode
- YouCompleteMe (Code-completion for Vim, but no official support on Windows)
- Supports in cygwin vim, using imported env variable from Windows. Currently found godef has limitation in cygwin to browse the code definition in $GOPATH/src(config problem?)
- godef issue in go v1.4
Need to update the godef and build it by self
Notepad++
- Gonpp
intellij
- Ref: http://www.cnblogs.com/clivelee/p/3870186.html
- golang plugin
- Setup Go project SDK
Gogland
JetBrains, commercial IDE, extends the IntelliJ platform
- Not formal release yet. Can download an early build for trial
Eclipse
- Goclipse
Wide
Zeus IDE
- TBD
LiteIDE
LiteIDE is a simple, open source, cross-platform Go IDE. Based on Qt5/Qt4
- easy installation and usage
- based on Qt, gui is not fashion style