Create the perfect GO development environment

Source: Internet
Author: User

Http://www.cnblogs.com/qgymje/p/3912259.html This originally is to the company to use go development of communication, mainly the installation of tools, with Markdown written, released the internal Gitlab, rushed to publish on the blog above , and did not change the format, now tidy up, and then add a little to explain the basic development tools sublime Text2 Download

Why use sublime Text2? I believe many developers like lightweight tools, lots of chrome pages and lots of small and fine software are like editor, but most of all, Vim mode!

Install the package control

When open, press CTRL + ~ to open the command line, or in view->show console, copy the following code to execute

Import Urllib2,os,hashlib; h = ' 7183a2d3e96f11eeadd761d777e62404 ' + ' e330c659d4bb41d3bdf022e94cab3cd0 '; PF = ' package control.sublime-package '; IPP = Sublime.installed_packages_path (); Os.makedirs (IPP) if not os.path.exists (IPP) else None; Urllib2.install_opener (Urllib2.build_opener (urllib2. Proxyhandler ())); by = Urllib2.urlopen (' http://sublime.wbond.net/' + pf.replace (', '%20 ')). read (); DH = hashlib.sha256 (by). Hexdigest (); Open (Os.path.join (IPP, PF), ' WB '). Write (by) if DH = = h else None; Print (' Error validating download (got%s instead of%s), please try manual install '% (DH, h) if DH! = H Else ' please rest Art Sublime Text to finish installation ')

Installing Gosublime, configuring

As the basis for the development of Go on St, must be installed, and then in the Settings-user write the following configuration, set a Golang workspace, so you can automatically prompt the import package of methods

{"    env": {        "Gopath": "~/workspace: $GS _gopath"    },    "Autocomplete_builtins": True,    "autocomplete _suggest_imports ": true}

Installing Golint

Golint is used to detect grammatical problems, similar to jslint, but it hints at most of the variable name is not underlined Ah, and then give a suggested variable name, to write comments ah ... Of course, after writing the comments, using the godoc-http=:8081 (port optional) can be seen in the browser just hard to write the comments have generated a document

Go get github.com/golang/lintgolint filename1 filepath1//can specify directories or files with multiple parameters

It can be deployed to Gosublime or Fswatch.

Installing Goimporter

This is a more powerful tool than GOFMT, it will automatically modify the import of the package, or is very practical, not because the import of things useless, or use a package without import caused by the error, this is a good thing to save time, product small into many

Go get code.google.com/p/go.tools/cmd/goimports

After compiling, set a ln-s to the $gobin directory (or copy the past), and add Gosublime user-setting a line, good things ah ~

"Fmt_cmd": ["Goimports"]

Note: ln-s requires absolute path

Fswatch Hot Compilation

Go get Github.com/codeskyblue/fswatch

After the same build is connected to $gobin, or directory such as/usr/bin, Windows users that are recommended to $gobin, compile the time to go to build directly, do not compile the individual fswatch.go, because there are multiple package main files

When a directory execution Fswatch is required, it is automatically generated. Fswatch.json
Then, in the command, write the commands that need to be executed, see below

{"    Paths": ["        ."    ],    "depth": 2,    "exclude": [],    "include": [        "\ \. ( GO|PY|PHP|JAVA|CPP|H|RB) $ "    ],    " command ": [        " Bash ",        "-C ",        " Pgrep server | Xargs Kill & & Golint./&& Go build server.go &&./server "    ],    " env ": {        " powerd_by ":" github.com/ Codeskyblue/fswatch "    },    " kill-signal ":" Kill "}

Note: command is written by itself, because this tool can not kill the startup process in my Mac, so I manually added the kill command, how to fix it is still studying the source code ~ ~

Incorporate golint into the monitoring directory for easy content modification

Supervisor
[Program:vehiclestat]command=~/workspace/yourprogramautostart = Trueautorestart = Truestartsecs = 5user = Rootredirect _stderr = Truestdout_logfile =/var/log/supervisord/yourprogram.log

A more practical tool for monitoring processes, compared with nohup./xxx & It's a little more reassuring.

Other

Set current directory to $gopath

Alias gopath= ' export gopath= ' pwd ' && echo $GOPATH '

Especially suitable for a number of different directory go projects, under each project run once Gopath, set up the current Gopath, very convenient

Summarize:

I do not know why, the previous version was actually moved first page, said to be original, this thing is my original Ah, although the tools are others, but the integration of these things also took a certain amount of energy AH!!!

Although there is idea + goplugin better plan, but still prefer to manually configure, so that the whole set down, go development environment is more complete, there is an egg pain is debugging, is the dispatch also keep log. Println ()??

Create the perfect GO development environment

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.