Golang environment configuration suggestions

Source: Internet
Author: User
Tags mercurial gocode

Golang environment configuration suggestions
Necessary features of the development environment

  1. Project Management
  2. Quick file jump
  3. Automatic syntax check
  4. Auto-completion
  5. Search Definition
  6. Fast startup
  7. Plug-ins can be written as needed

(Project, lint, hint, autocomplete)

To implement the above configuration, we will proceed step by step.

My Environment
  1. OSX
  2. GO 1, 1.4
  3. HomeBrew
Go environment Installation

This part is the most important. Without it, it is really sad that too assumerrors appears during each build.

  1. Environment configuration: (golint, goOracle, mercurial)
    • Install mercurial: brew install mercurial

      This item is used for version management and is also a tool for downloading code similar to git. It seems that many google projects are used.

    • Install golint:
      1. $ Go get github.com/golang/lint
      2. $ Go install github.com/golang/lint
  2. Install gooracle
    1. Go get code.google.com/p/go.tools/#/oracle
  3. Install goimport
    1. Go get golang.org/x/tools/#/goimports
  4. Install gocode
    1. Go get-u github.com/nsf/gocode
  5. Install godef
    1. Go get-v code.google.com/p/rog-go/exp/#/godef
    2. Go install-v code.google.com/p/rog-go/exp/#/godef
  6. 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

  7. 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 /.

  8. Final configuration result (Package-> Go Plus-> Display Go Information after installation)

    1. CoverTool:/usr/local/go/pkg/tool/darwin_amd64/cover
    2. VetTool:/usr/local/go/pkg/tool/darwin_amd64/vet
    3. FormatTool:/Users/Li-jianying/git/bin/goimports
    4. LintTool:/usr/local/go/bin/golint
    5. GocodeTool:/Users/Li-jianying/git/bin/gocode
    6. GocodeStatus: Enabled
    7. OracleTool:/Users/Li-jianying/git/bin/oracle
    8. Git:/usr/bin/git
    9. Mercurial:/usr/local/Cellar/mercurial/3.2.1/bin/hg
    10. 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
  1. Plug-in: project-manager

    This plug-in is very hot and ranks very top on the home page of atom. io.

  2. 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.

  3. 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.

  4. Press the shortcut key to display the effect:

Automatic syntax check and Automatic completion
  1. Plug-in go-plus, autocomplete-plus (dependance), gocode
    Install apm install. The speed is also acceptable.

  2. 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.

  3. 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.
  4. Demo after installation (similar to go-plus official demo)

  5. 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:
      1. '. Active. pane ':
      2. 'Ctrl-; ': 'gocode: toggle'
    • Effect demonstration
Search Definition
  1. Plug-in godef
  2. 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
  1. I just summarized all the golang-related atom plug-ins I used here.
  2. Believe that golang's use of the editor is sufficient. This is because the go tool is too easy to use.
My key map
  1. Cmd-d duplicate line
  2. Cmd-w disable tags
  3. List of labels in the cmd-r File
  4. Cmd-e use the selected content as the search pattern
  5. Shift-cmd-f project internal search, which is very practical. Command configuration (keymap. cson)
    1. '. Platform-darwin atom-text-editor ':
    2. 'Shift-cmd-d': 'Find-and-replace: select-next'
Thanks to golang
  1. 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.
  2. 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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.