Golang Development Environment
Installation
- Download go
- Go Complier: - offcial: gc
- GNU GC: gccgo
 
- Go supports 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. x86orx86-32); 8g,8l,8c(Plan9 gc),8a
- arm (a.k.a. ARM); 5g,5l,5c(Plan9 gc),5a. Now supports 64-bit ARM architecture on FreeBSD 12.0 or later (the freebsd/arm64 port).
- Experimental support for 64-bit RISC-V on Linux (GOOS=linux, GOARCH=riscv64)
 
- 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).
 
 
- GVM
- Reference in astaxie/build-web-application-with-golang
Tools
IDE
GOPROXY
- Set to Goproxy China
- default value: GOPROXY=https://proxy.golang.org,direct
| 1 | $ go env -w GO111MODULE=on | 
done.
macOS or Linux
Open your terminal and execute
| 1 | $ export GO111MODULE=on | 
or
| 1 | $ echo "export GO111MODULE=on" >> ~/.profile | 
done.
Windows
Open your PowerShell and execute
| 1 | C:\> $env:GO111MODULE = "on" | 
gopls
- It is widely used in vscode, vim/neovim for golang IDE.- gopls (pronounced: “go please”) is the official language server for the Go language.
- It is currently in alpha, so it is not stable. Aiming stable in the first half of 2020.
 
- Installation- By vscode or vim-go
- Manually- Set GOPROXY in above steps.
- go get golang.org/x/tools/gopls@latest, note, don’t use- -uoption to keep it compatible.
 
 
- Problems of gopls- slow in searching implemenations of interface, callers and callees.
- CPU and memory consuming (2G ~ 4G).
 
Vscode/insiders
- Install Go plugin with tools (gopls, godef, gorename…)- command palette: “Go:install/update tools”
 
- Setup Configuration
| 1 | "go.autocompleteUnimportedPackages": true, | 
Vim
- vim-go- PluginInstall- Plug: Plug ‘fatih/vim-go’, { ‘do’: ‘:GoUpdateBinaries’ }
- Vundle: Plugin ‘fatih/vim-go’
 
- GoInstallBinaries/GoUpdateBinaries
- 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)
 
- PluginInstall
- Tutorial- GoGuruScope
 
- Configurations
| 1 | let g:go_auto_type_info = 1 | 
- Useful Commands - gd/CTRL-]: GoDef
- CTRL-o
- :GoReferrers
- :GoDescribe
- :GoImplementes
- :GoChannelPeers
- :GoCallees
- :GoCallers
- :GoGuruScope
- :GoInfo
- :GoSameIds/:GoSameIdsClear
 
- 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  1 
 2
 3" Golang 
 au BufNewFile,BufRead *.go setf go
 autocmd FileType go setlocal omnifunc=go#complete#Complete- autocompletion is based on the gocode, when golang upgrade, please upgrade the gocode bygo get -u github.com/nsf/gocode
 
- autocompletion is based on the 
 
- Add config to vimrc to support invoke gocode for code completion  
- YouCompleteMe (Code-completion for Vim, but no official support on Windows) 
- References 
| 1 | " Golang | 
- 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?) 
- 
- Need to update the godef and build it by self
 
Gogland
- JetBrains GO IDE- Disable parameter name hint (Editor -> General -> Appearance)
 
sublime
- Install package control- “ctrl + `“ or Menu: View -> Show console: input
 
| 1 | 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
 
- ctrl+shift+p -> input install
| 1 | { | 
- 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)
 
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
版权声明:本博客所有文章除特殊声明外,均采用 CC BY-NC 4.0 许可协议。转载请注明出处 Kasper Deng的博客!