Golang environment configuration suggestions
Necessary features of the development environment
- Project Management
- Quick file jump
- Automatic syntax check
- Auto-completion
- Search Definition
- Fast startup
- Plug-ins can be written as needed
(Project, lint, hint, autocomplete)
To implement the above configuration, we will proceed step by step.
My Environment
- OSX
- GO 1, 1.4
- HomeBrew
Go environment Installation
This part is the most important. Without it, it is really sad that too assumerrors appears during each build.
- Environment configuration: (golint, goOracle, mercurial)
- Install gooracle
- Go get code.google.com/p/go.tools/#/oracle
- Install goimport
- Go get golang.org/x/tools/#/goimports
- Install gocode
- Go get-u github.com/nsf/gocode
- Install godef
- Go get-v code.google.com/p/rog-go/exp/#/godef
- Go install-v code.google.com/p/rog-go/exp/#/godef
- During environment installation, downloading may often fail, probably because my network is not good. Problems frequently occur when connecting to google.
Solution:
Golang China's download channel has a third-party package download tool. After you enter the address, people will provide you with a tar package to download.
Put it in gopath.
This step can only replace the go get step, and the go install
After go install, various tool files will appear in $ GOPATH/bin /.
- Gocode provides Code Completion
- Godef code jump
- Automatic gofmt code sorting
- Golint code syntax check
- Goimports Automatic Sorting imports
- Oracle code callgraph query (plugin is still in todolist, but an error is reported without configuration. It's annoying .)
Finally, do not forget to copy the above command to $ GOROOT/bin /.
Final configuration result (Package-> Go Plus-> Display Go Information after installation)
- CoverTool:/usr/local/go/pkg/tool/darwin_amd64/cover
- VetTool:/usr/local/go/pkg/tool/darwin_amd64/vet
- FormatTool:/Users/Li-jianying/git/bin/goimports
- LintTool:/usr/local/go/bin/golint
- GocodeTool:/Users/Li-jianying/git/bin/gocode
- GocodeStatus: Enabled
- OracleTool:/Users/Li-jianying/git/bin/oracle
- Git:/usr/bin/git
- Mercurial:/usr/local/Cellar/mercurial/3.2.1/bin/hg
- PATH:/usr/local/bin:/usr/sbin:/usr/local/go/bin
There is no problem if there is no red line.
Project management, automatic file redirection
- Plug-in: project-manager
This plug-in is very hot and ranks very top on the home page of atom. io.
- Usage Details:
- Use tree view (cmd-\) to open and close the project file.
- Search for project files (cmd-t)
Enter keywords in sequence, for example, go source code in the user module's controll. When searching, you can use multiple Shortcut Keys = "user controll go" to find the source code accurately.
- Open the project list (ctrl-cmd-p)
Then a project list is displayed and you can open the project by pressing enter.
Summary:
I feel that the treeview of this plug-in is not very useful, because there are many project files in normal projects.
But it is very convenient to quickly open a project (folder), and it is quite cool to quickly open a file.
Press the shortcut key to display the effect:
Automatic syntax check and Automatic completion
Plug-in go-plus, autocomplete-plus (dependance), gocode
Install apm install. The speed is also acceptable.
When saving the Usage Details
- Imports is automatically added.
- The code is automatically sorted
For example, a: = 5 will become a: = 5
Two blank lines are automatically converted into one space.
- Lint automatically checks syntax errors (go build errors are displayed)
- Vet automatically checks the syntax and spelling suggestions.
Function. The struct will prompt comments.
For example, you will be prompted to add a godoc-type comment before the function: // functionname
The first line of the annotation. Use a double slash to annotate + space + function name + space + SHORT function description.
Usage Details: during editing
- Go-plus and autocomplete-plus will automatically fill in all-inclusive names (tab completion, press enter will not work, this is really comfortable)
- Package name. Then, enter several letters at the beginning of the method name to provide complete suggestions.
Demo after installation (similar to go-plus official demo)
Demo of Automatic completion of the gocode plug-in
- This plug-in is inherited from autocomplete because it is out of repair. The api is in the old version, so api warnings are always prompted. (I turn a blind eye to it)
- If the gocode cannot be found, go to the code and find the 105 lines in the file autocomplete-view.coffee to write the absolute path.
- Bind a shortcut key. Because this plug-in does not have a file (keymap) bound to the shortcut key, you need to manually bind the configuration in keymap. cson as follows:
- '. Active. pane ':
- 'Ctrl-; ': 'gocode: toggle'
- Effect demonstration
Search Definition
- Plug-in godef
- Usage Details: When the cursor is on the target code, use the shortcut key ctrl-k to jump to the definition code of the target code.
Summary
- I just summarized all the golang-related atom plug-ins I used here.
- Believe that golang's use of the editor is sufficient. This is because the go tool is too easy to use.
My key map
- Cmd-d duplicate line
- Cmd-w disable tags
- List of labels in the cmd-r File
- Cmd-e use the selected content as the search pattern
- Shift-cmd-f project internal search, which is very practical. Command configuration (keymap. cson)
- '. Platform-darwin atom-text-editor ':
- 'Shift-cmd-d': 'Find-and-replace: select-next'
Thanks to golang
- Golang can have such a development experience and perform so well in such a low version. It is really the best gift that Daniel has given us.
- Golang has such a good development tool and a variety of highly scalable editors (vim, emacs, sublime, atom, etc.
This article permanently updates the link address: