This is a creation in Article, where the information may have evolved or changed. This is originally for the company to use go development of communication, mainly the installation of tools, with Markdown written, released the internal Gitlab, rushed to publish to the blog above, did not change what format, now tidy up, and then add a little explanation
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
ImportUrllib2,os,hashlib; h ='7183a2d3e96f11eeadd761d777e62404'+'e330c659d4bb41d3bdf022e94cab3cd0'; PF ='Package Control.sublime-package'; IPP = Sublime.installed_packages_path (); Os.makedirs (IPP)if notOs.path.exists (IPP)ElseNone; 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)ifDH = = hElseNone;Print('Error validating download (got%s instead of%s), please try manual install'% (DH, h)ifDH! = hElse 'Restart 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//You 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/== = 5 = = =/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 ()???