1.4 Go development tool
In this section I'll introduce several development tools that have automated prompts to automate the FMT functionality. Because they are cross-platform, the installation steps are generic. Liteide
Liteide is a cross-platform lightweight integrated development Environment (IDE) developed specifically for the Go language, written by VISUALFC.
Figure 1.4 Liteide Main interface
liteide Main Features: support the mainstream operating system Windows Linux MacOS X Go compilation environment management and switching management and switching multiple go compilation environment support Go language cross-compile project management approach consistent with Go standard based on Gopath package browser based on Gopath compiler system based on Gopath API document retrieval Go Language Editor support class browser and outlining Gocode (Code completion tool) Perfect support go language document viewing and API quick Retrieve code expression information display F1 source code definition Jump Support F2 GDB breakpoints and debugging support GOFMT automatic formatting support for other features support multi-national language interface display full plug-in architecture support editor color scheme based on Kate's syntax display support for Full-text-based word autocomplete support for keyboard shortcuts binding schemes Markdown document editing support Live Preview and sync display custom CSS display exportable HTML and PDF documents bulk conversion/merging into html/pdf documents
liteide Installation Configuration
Liteide installation Download address Http://code.google.com/p/golangide Source Address Https://github.com/visualfc/liteide
First install the Go language environment, and then according to the operating system download liteide corresponding compressed file directly decompression can be used.
Install Gocode
Enabling the Enter auto completion of the Go language requires installation of Gocode:
Go get-u github.com/nsf/gocode
Compilation environment settings
Switch and configure liteide currently used environment variables according to your system requirements.
With Windows operating system, 64-bit go language, for example, choose Win64 in the Environment configuration of the toolbar, point edit Environment, enter liteide edit win64.env file
Goroot=c:\go
gobin=
goarch=amd64
goos=windows
cgo_enabled=1
path=%gobin%;%goroot%\bin;% path% ...
Modify the Goroot=c:\go to the current go installation path, save the disk, and, if there is a MinGW64, add c:\MinGW64\bin to the path so that going calls GCC supports CGO compilation.
To Linux operating system, 64-bit go language For example, the toolbar's environment configuration to select Linux64, point editing Environment, into liteide edit linux64.env file
goroot= $HOME/go
gobin=
goarch=amd64
goos=linux cgo_enabled=1 path=
$GOBIN: $GOROOT/bin:$ PATH
...
Change the goroot= $HOME/go to the current go installation path and save the disk.
Gopath settings
The Go Language tool chain uses the Gopath setting, which is a list of project paths developed in the Go language, entered on the command line (also CTRL + in Liteide, direct input) go to help Gopath quickly view Gopath documentation.
You can easily view and set the Gopath in Liteide. Through the menu-view-gopath settings, you can view the list of Gopath that already exists on your system, and add the project directory to your custom Gopath list as needed. Sublime Text
Here will introduce the combination of Sublime Text 2 (hereinafter referred to as sublime) +gosublime+gocode+margo, so why choose this combination.
The automation prompt code, as shown in the following illustration
Figure 1.5 Sublime Automation prompt interface
When you save, automatically format the code, so that you write code more beautiful, in line with go standards.
Support Project Management
Figure 1.6 Sublime Project management interface
Support Syntax highlighting
Sublime Text 2 is free to use, just save the number of times to reach a certain number will be prompted whether to buy, click Cancel continue to use, and the official registered version without any difference.
Then start talking about how to install, download sublime
According to their corresponding system download the corresponding version, and then open Sublime, for unfamiliar sublime students can first look at this article Sublime Text 2 Introduction and Skills
After opening, install Package control:ctrl+ Open the command line and execute the following code:
Import Urllib2,os; 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 ())); Open (Os.path.join (IPP,PF), ' WB '). Write (Urllib2.urlopen (' http://sublime.wbond.net/' +pf.replace ('), '%20 '). Read () ); print ' Please restart Sublime Text to finish installation '
This time restart sublime, you can find in the menu bar more than a column below, indicating that package control has been installed successfully.
Figure 1.7 Sublime Package Management
Next, install Gocode and Margo. Open the terminal to run the following code (requires git)
Go to Github.com/nsf/gocode go get
Github.com/disposaboy/margo
At this point we will find that there are two more executables, Gocode and Margo below the $gopath/bin, which will start automatically when Gosublime load. After installation, you can install the sublime plugin. To install Gosublime, sidebarenhancements and go builds, remember to reboot the sublime after installing the plugin, ctrl+shift+p to open Package controll input PCIP (that is, "Package Control:install Package "abbreviation).
At this point, the bottom left-hand corner shows that the packet data is being read, and the following interface appears after completion
Figure 1.8 Sublime Install plugin interface
This time enter gosublime, press OK to begin to install. Applies equally to sidebarenhancements and go builds. Verify that the installation is successful, you can open the sublime, open the Main.go to see if the syntax is highlighted, import is not automated prompts, import "FMT" after the input fmt. Is there a function in the automation hint?
If this is already the case, it means that you have completed the installation and the automatic prompts are complete.
If there is no such hint, generally your $path is not configured correctly. You can open the terminal, input gocode, is not able to run correctly, if not to explain $path is not configured correctly. Vim
Vim is developed from the VI of a text editor, code completion, compilation and error jump, such as convenient programming features particularly rich, in the programmer is widely used.
Figure 1.9 Vim Editor automation hint Go interface
Configure VIM highlighting
Cp-r $GOROOT/misc/vim/* ~/.vim/
Add syntax highlighting in ~/.VIMRC files
FileType plugin indent on
syntax on
Install Gocode
Go get-u github.com/nsf/gocode
The Gocode is installed under $gobin by default.
Configure Gocode
~ CD $GOPATH/src/github.com/nsf/gocode/vim ~
/update.bash
~ Gocode Set Propose-builtins true
Propose-builtins true
~ Gocode set Lib-path "/home/border/gocode/pkg/linux_amd64
lib-path"/home/border/ Gocode/pkg/linux_amd64 "
~ Gocode set
propose-builtins true
lib-path"/home/border/gocode/pkg/linux_ AMD64 "
The implication of the two parameters inside the Gocode set is:
Propose-builtins: Automatically prompt for Go's built-in functions, types, and constants, default to False, not prompt.
Lib-path: By default, Gocode searches only for packages $GOPATH/pkg/$GOOS _$goarch and $GOROOT/pkg/$GOOS _$goarch directory. Of course, this setting is where we can set additional LIB access paths
Congratulations, installation completed, you can now use: E Main.go experience the fun of developing go. Emacs
An artifact in the legendary Emacs, she is not just an editor, it is a consolidated environment, or it can be called an integrated development environment, which allows users to stay in a fully functional operating system.
Figure 1.10 Emacs Edit Go Main interface
Configure Emacs Highlighting
CP $GOROOT/misc/emacs/* ~/.emacs.d/
Install Gocode
Go get-u github.com/nsf/gocode
Gocode the default installation to the $gobin underneath.
Configure Gocode
~ CD $GOPATH/src/github.com/nsf/gocode/emacs
~ CP go-autocomplete.el ~/.emacs.d/
~ Gocode Set Propose-builtins True
propose-builtins true
~ Gocode set Lib-path "/HOME/BORDER/GOCODE/PKG/LINUX_AMD64"///change to your own path
Lib-path "/home/border/gocode/pkg/linux_amd64"
~ Gocode set
propose-builtins true
lib-path "/home/ Border/gocode/pkg/linux_amd64 "
Need to install Auto completion
Download AutoComplete and Unzip
~ Make install dir= $HOME/.emacs.d/auto-complete
Configuring ~/.emacs Files
;; Auto-complete
(Require ' Auto-complete-config)
(add-to-list ' ac-dictionary-directories ' ~/.emacs.d/ Auto-complete/ac-dict ")
(Ac-config-default)
(Local-set-key (kbd" m-/") ' Semantic-complete-analyze-inline)
(Local-set-key ".") ' Semantic-complete-self-insert '
(local-set-key ">" "Semantic-complete-self-insert")
More Information reference: Http://www.emacswiki.org/emacs/AutoComplete
Configuration. Emacs
;; Golang mode (Require ' go-mode-load) (Require ' go-autocomplete) Speedbar;;
(Speedbar 1)
(speedbar-add-supported-extension ". Go") (Add-hook ' Go-mode-hook ' (lambda ();; Gocode (Auto-complete-mode 1) (setq ac-sources ' (ac-source-go)) Imenu & Speedbar (setq imenu-generic-expression ' ("type" ^type *\\ ([^ \t\n\r\f]*\\) "1)" ("Func") "^func *\\ (. *\\) {" 1))) (Imenu-add-to-menubar "Index") Outline mode (make-local-variable ' Outline-regexp) (setq outline-regexp "//\\.\\|//[^\r\n\f][^\r\n\f]\\|pack\\|fun c\\|impo\\|cons\\|var.\\|type\\|\t\t* ... ") (Outline-minor-mode 1) (Local-set-key" \m-a "outline-previous-visible -heading) (local-set-key "\m-e" ' outline-next-visible-heading)
Menu bar (Require ' Easymenu) (Defconst go-hooked-menu ' ("Go Tools" ["Go Run"]
["Go reformat buffer" Go-fmt-buffer T]
["Go check buffer" Go-fix-buffer T])
(Easy-menu-define Go-added-menu (Current-local-map) "Go Tools" go-hooked-menu) Other (setq show-trailing-whitespace t)) Helper function (Defun go () ' Run current buffer ' (interactive) (Compile (concat "Go Run" (buffer-file-name)) ))
;; Helper function (Defun go-fmt-buffer () "Run gofmt on current buffer" (interactive) (If Buffer-read-only ( Progn (Ding) (message ' Buffer is read Only ') (Let (P (line-number-at-pos)) (filename buffer-fil E-name)) (Old-max-mini-window-height max-mini-window-height)) (Show-all) (if (get-buffer) *go Reformat
Errors* ") (Progn (delete-windows-on" *go reformat errors* ") (kill-buffer" *go reformat errors* ")))
(setq max-mini-window-height 1)
(If (= 0 (Shell-command-on-region (point-min) (Point-max) "Gofmt" "*go reformat output*" nil "*go reformat Errors*" t)) (Progn (Erase-buffer) (insert-buffer-substring"*go reformat output*") (Goto-char (Point-min)) (Forward-line (1-p))) (With-current-buffer "*go refor
Mat errors* "(Progn (Goto-char (Point-min)) (while Re-search-forward" <standard input> "nil t)
(replace-match filename))
(Goto-char (Point-min))
(Compilation-mode)))
(setq max-mini-window-height old-max-mini-window-height)
(delete-windows-on "*go reformat output*")
(kill-buffer "*go reformat output*"))) ;; Helper function (Defun go-fix-buffer () "Run Gofix on current buffer" (interactive) (Show-all) (Shell-comm
And-on-region (point-min) (Point-max) "Go Tool Fix-diff")
Congratulations, you can now experience the fun of developing go in artifacts. The default speedbar is closed, if open need to be put;; (Speedbar 1) The previous annotation is removed, or it can be manually opened via M-x Speedbar. Eclipse
Eclipse is also a very common development tool, and here's how to use Eclipse to write go programs.
Figure 1.11 Eclipse edit Go's main interface
First, download and install eclipse
Download Goeclipse Plugin
Http://code.google.com/p/goclipse/wiki/InstallationInstructions
Download Gocode, code completion tips for Go
Gocode's GitHub Address:
Https://github.com/nsf/gocode
To install git under windows, you typically use the Msysgit
Install again under cmd:
Go get-u github.com/nsf/gocode
You can also download the code, compile it directly with the go build, and generate Gocode.exe
Download MinGW and install them as required.
Configuring Plug-ins
Windows->reference->go
(1). Configure the Go Compiler
Figure 1.12 Setting some basic information for go
(2). Configure Gocode (optional, code completion), set the Gocode path to the Gocode.exe file generated before
Figure 1.13 Setting up Gocode information
(3). Configure GDB (optional, make a trial), set the GDB path to the MinGW installation directory Gdb.exe files
Figure 1.14 Setting up GDB information
Whether the test was successful
Create a new Go project and build a hello.go. The following figure:
Figure 1.15 New Project Edit file
Debug as follows (to be debugged with input commands in the console):
Figure 1.16 Debug Go program IntelliJ Idea
Readers familiar with Java should be unfamiliar with idea, which is a plugin to support the Go language highlighting syntax, code hints and refactoring implementations.
First download Idea,idea support multi-platform: Win,mac,linux, if you have the money to buy a formal version, if not the use of Community free version, for just the development of the Go language free edition is enough to use
Install Go plugin, click Setting in the menu file, find plugins, click, broswer Repo button. Domestic users may be an error, their own solution ha.
At this time will see a lot of plug-ins, search find Golang, double-click, download and install. Wait until the Golang line appears behind the downloaded flag, click OK.
Then click Apply. The IDE will ask you to reboot.
When you restart, creating a new project finds that you can create a Golang project:
Next, you will be asked to enter the Go SDK location, generally installed in the C:\go,linux and Mac according to their own installation directory settings, select the directory to determine, you can. Links Directory previous section: Go command next section: summary