1.4 go development tools
This section describes several development tools with automated prompts and FMT functions. Because they are both cross-platform, the installation steps and the like are generic.
Liteide
Liteide is a lightweight cross-platform integrated development environment (IDE) specially developed for the go language, written by visualfc.
Figure 1.4 Main liteide Interface
Main features of liteide:
- Supports mainstream operating systems
- Go compiling environment management and switching
- Manage and switch multiple go compiling Environments
- Support for cross-Compiling in go Language
- Consistent with the go standard project management method
- Gopath-based package Browser
- Gopath-based compilation system
- Gopath-based API Document Retrieval
- Go language editing support
- Class browser and outline display
- Perfect support for gocode (Automatic Code Completion tool)
- Go document viewing and quick API Retrieval
- Code Expression Information Display
F1
- Support for source code definition redirection
F2
- GDB breakpoint and debugging support
- Support for automatic gofmt formatting
- Other features
- Supports multi-language interface display
- Complete plug-in architecture
- Supports the color scheme of the editor.
- Support for Kate-based syntax display
- Automatic completion of full-text-based words
- Support for keyboard shortcut key binding
- Markdown document editing support
- Real-time preview and synchronous display
- Custom CSS display
- Export HTML and PDF documents
- Batch conversion/merging into HTML/PDF documents
Liteide installation Configuration
Liteide Installation
- Http://code.google.com/p/golangide
- Source Code address https://github.com/visualfc/liteide
First, install the go language environment, and then download the corresponding liteide compressed file based on the operating system to decompress it.
Install gocode
To enable the go language input, you need to install gocode:
go get -u github.com/nsf/gocode
Compiling environment settings
Switch and configure the environment variables currently used by liteide according to your system requirements.
In Windows, the 64-bit go language is used as an example. In the environment configuration of the toolbar, select win64, clickEdit Environment, Go to liteide to edit the win64.env File
GOROOT=c:\goGOBIN=GOARCH=amd64GOOS=windowsCGO_ENABLED=1PATH=%GOBIN%;%GOROOT%\bin;%PATH%。。。
ReplaceGOROOT=c:\goChange to the current go installation path and save the disk. If you have mingw64, you canc:\MinGW64\binAdd the path so that go calls GCC to support CGO compilation.
In Linux, the 64-bit go language is used as an example. In the environment configuration of the toolbar, select linux64, clickEdit Environment, Go to liteide to edit the linux64.env File
GOROOT=$HOME/goGOBIN=GOARCH=amd64GOOS=linuxCGO_ENABLED=1PATH=$GOBIN:$GOROOT/bin:$PATH 。。。
ReplaceGOROOT=$HOME/goChange to the current go installation path and save the disk.
Gopath settings
The tool chain in the go language is set using gopath. It is a list of project paths developed in the go language and can be entered in the command line (in liteide, you can alsoCtrl+,Input directly)go help gopathQuick View of gopath documentation.
You can conveniently view and set gopath in liteide. PassMenu-View-gopathTo view the existing gopath list in the system, and add the project directory to the custom gopath list as needed.
Sublime text
Here we will introduce the combination of sublime text 2 (sublime) + gosublime + gocode + Margo. Why do we choose this combination?
Automated prompt code, as shown in
Figure 1.5 sublime automated prompt page
The code is automatically formatted when it is saved, making the code you write more beautiful and compliant with the go standard.
Support Project Management
Figure 1.6 sublime Project Management page
Supports syntax highlighting
Sublime text 2 is available for free. After the number of storage times reaches a certain level, you will be prompted whether to purchase it. Click Cancel to continue using it, which is no different from the official registration version.
Next, let's talk about how to install and download sublime.
Download the corresponding version based on your own system, and then open sublime. If you are not familiar with sublime, you can take a look at the sublime text 2 entry and tips in this article.
Install package control: Ctrl + on the command line and run 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'
At this time, restart sublime and you will find that there is an additional topic in the menu bar, indicating that package control has been installed successfully.
Figure 1.7 sublime package management
Next, install gocode and Margo. Open the terminal and run the following code (GIT required)
go get github.com/nsf/gocodego get github.com/DisposaBoy/MarGo
At this time, we will find that$GOPATH/binThere are two executable files, gocode and Margo, which will be automatically started when the gosublime is loaded.
- After installation, you can install the sublime plug-in. Gosublime, sidebarenhancements, And go build must be installed. After installing the plug-in, remember to restart sublime to take effect. Press Ctrl + Shift + P to open the package controll input.
pcip("Package control: Install package ).
At this time, the lower left corner shows that the package data is being read. After the package is read, the following interface is displayed:
Figure 1.8 sublime plug-in installation page
At this time, enter gosublime and press OK to start the installation. This applies to sidebarenhancements and go build.
- Verify whether the installation is successful. You can open sublime, open main. Go, and check whether the syntax is highlighted. Enter
importAutomated prompt,import "fmt"Enterfmt.Is there a function automatically prompted.
If this prompt appears, it indicates that the installation is complete and the automatic prompt is displayed.
If this prompt is not displayed, it is generally yours.$PATHNot configured correctly. You can open the terminal and enter gocode to see if it can run correctly.$PATHNot configured correctly.
Vim
Vim is a text editor developed from VI. It provides rich programming functions such as code completion, compilation, and error redirection, and is widely used by programmers.
Figure 1.9 go page for automatic prompt in the vim Editor
Configure Vim highlight
cp -r $GOROOT/misc/vim/* ~/.vim/
In ~ /Add syntax highlighting in the vimrc File
filetype plugin indent onsyntax on
Install gocode
go get -u github.com/nsf/gocode
Gocode is installed$GOBINBelow.
Configure gocode
~ cd $GOPATH/src/github.com/nsf/gocode/vim~ ./update.bash~ gocode set propose-builtins truepropose-builtins true~ gocode set lib-path "/home/border/gocode/pkg/linux_amd64"lib-path "/home/border/gocode/pkg/linux_amd64"~ gocode setpropose-builtins truelib-path "/home/border/gocode/pkg/linux_amd64"
Meanings of the two parameters in gocode set:
Propose-builtins: Indicates whether to automatically prompt go built-in functions, types, and constants. The default value is false.
Lib-path: by default, gocode only searches$ Gopath/PKG/$ GOOS _ $ goarchAnd$ Goroot/PKG/$ GOOS _ $ goarchThe package under the directory, of course, this setting is to set the path that our additional lib can access
Congratulations, the installation is complete. You can use:e main.goExperience the fun of developing go.
Emacs
The legendary Emacs artifact is not just an editor. It is an integrated environment, or can be called an integrated development environment. Such features put users in a full-featured operating system.
Figure 1.10 edit the Go Main Interface of Emacs
Configure Emacs to highlight
cp $GOROOT/misc/emacs/* ~/.emacs.d/
Install gocode
go get -u github.com/nsf/gocode
Gocode is installed$GOBIN.
Configure gocode
~ CD $ gopath/src/github.com/nsf/gocode/emacs ~ CP go-autocomplete.el ~ /. Emacs. d /~ Gocode set propose-builtins truepropose-builtins true ~ Gocode set Lib-path "/home/border/gocode/PKG/linux_amd64" // replace it with your own path Lib-path "/home/border/gocode/PKG/linux_amd64 "~ Gocode setpropose-builtins truelib-path "/home/border/gocode/PKG/linux_amd64"
Auto completion needs to be installed
Download AutoComplete and decompress it
~ make install DIR=$HOME/.emacs.d/auto-complete
Configuration ~ /. Emacs file
;;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)
Reference: http://www.emacswiki.org/emacs/AutoComplete
Configure. 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\\|func\\|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 buffer" go t] ["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-file-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 Reformat 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-command-on-region (point-min) (point-max) "go tool fix -diff"))
Congratulations, you can now experience the fun of developing go in the arms. By default, speedbar is disabled. If you want to enable it, remove the comment in front of; (speedbar 1), or useM-x speedbarManually enable.
Eclipse
Eclipse is also a very common development tool. The following describes how to use eclipse to compile go programs.
Figure 1.11 main interface for eclipse to edit go
First download and install eclipse
Download the goeclipse plug-in
Http://code.google.com/p/goclipse/wiki/InstallationInstructions
Download gocode to complete the code prompts for go.
GitHub address of gocode:
https://github.com/nsf/gocode
Install git in windows, usually using msysgit
Then install it in cmd:
go get -u github.com/nsf/gocode
You can also download the code and compile it using go buildto generate gocode.exe.
Download mingw and install it as required
Configure plug-ins
Windows> reference> go
(1) configure the go Compiler
Figure 1.12 configure basic go Information
(22.16.configure gocode(optional, complete the code and set gocode.exe file as the previous file
Figure 1.13 set gocode
(32.16.configure gdb(optional, used as an example, set gdb.exe to the gdb.exe file under the mingwinstallation directory
Figure 1.14 set GDB Information
Test successful
Create a go project and create a hello. Go project. For example:
Figure 1.15 create a project and edit a file
Debugging is as follows (you need to run the following command on the console ):
Figure 1.16 debug the go Program
Intellij idea
Readers familiar with Java should be familiar with idea. Idea uses a plug-in to support the highlighted syntax, code prompts, and refactoring of the Go language.
Download idea first. Idea supports multiple platforms: Win, Mac, and Linux. If you have money, you can buy the official version. If not, you can use the free version of the community. For development of the go language, the free version is enough.
Install the go plug-in, click setting in the menu file, find plugins, and click the broswer repo button. Domestic users may report an error and solve it by themselves.
At this time, you will see many plug-ins, search for golang, double-click, download and install. Click OK when the downloaded mark appears next to the golang line.
Click Apply. At this time, the IDE will ask you to restart.
After restarting, you can create a golang project after creating a new project:
In the next step, you are required to enter the go SDK location, which is generally installed in c: \ go. For Linux and Mac, select the directory based on your installation directory settings.
Links
- Directory
- Previous section: Go commands
- Next section: Summary