First, preface
Recently I have a job transfer, entered a brand-new field [Golang] server development. Write this article, I hope to those who have not contacted Golang development and debugging environment and still hesitate to choose the Golang IDE and tangled friends a little help, if you have benefited from this and also have a blog Park account, I sincerely hope to get you a small [recommended] for encouragement.
My operating system is Windows 8.1 64bit, the development tools are selected as follows:
Go1.4.2.windows-amd64
Sublime Text 2 (Plug-in gosublime/gogdb)
GDB, GCC (can be included after installing MINGW-W64)
Git
Second, Golang installation
Download the Golang version you need, I download go1.4.2.windows-amd64.zip extract to c \ disk
= Config Golang environment variable =
Goarch=amd64
Goos=windows
Goroot=c:\go
Gopath=e:\goproj
Gobin=%gopath%\bin
Add to Path environment variable;%goroot%\bin
Open the command line and enter go version to see that the Golang installation is successful.
Note : Gopath is a special path to the Golang project, and its path must contain 3 directories such as bin, pkg, and SRC as shown:
The Golang project relies on the SRC directory to organize the source code.
Third, install sublime Text 2 configuration Gosublime/gogdb
Here's why you can't choose ST3, because before using ST3 install gogdb plugin times wrong "It seems you ' re not running GDB with the" Mi "interpreter. Please add # "--interpreter=mi" to your GDB command line "When I checked the task manager I found that the GDB process was actually shipped with the--interpreter=mi parameter, and finally I chose to retreat to ST2 .... 囧
Download ST2 open it after installation
Sublime Text 2 interface diagram
1. Tap View–show console or press CTRL + ' eject console
Enter the following text to press Enter and restart ST2:
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 ' Restart Sublime Text to finish installation '
2. When you press ctrl+shift+p, a text box will pop up to enter the command.
3. Enter Install to press ENTER
Here, wait a little bit.
4. Once again, a command input box will appear, at which point enter Gosublime press ENTER to install the plugin.
5. Install the gogdb in the same vein.
Now that we have installed the GOGDB and Gosublime plug-ins, we need to download the installation Gocode to enable it to support IntelliSense. (Does not install the Gocode seems to be able to use a part of IntelliSense)
6. Open cmd, enter go get github.com/nsf/gocode press ENTER after waiting for a moment, open%gopath%\bin This path should be able to see gocode.exe this file, if you do not see the Go install Github.com/nsf/gocode try it.
7. Then cut the Gocode.exe into the%goroot%\bin below, before we have added the%goroot%\bin to the PATH environment variable, so that the copy action will ensure that Gocode.exe is under the PATH environment variable.
You can configure the ST2 Gosublime plugin after you are ready for Gocode!
8. Click Preferences > Package Settings > Gosublime > Settings–default
9. Set ENV
10. Create a new folder, then open it with ST2 and build the main.go empty file, then you can enable IntelliSense.
Write Golang code ...
package main
import (
"fmt"
)
func main () {
i: = 10000
j: = 86
k: = i + j
fmt.Println (k)
fmt.Println ("Hello world. Hello world!")
}
11. Press Ctrl+b to open the console input go install can get higo.exe under%gopath%\bin, execute it to see the input.
It is very important to start the GOGDB configuration work now.
We first check whether GDB is installed on this machine, the method is to enter GDB on the cmd command line, if you see that the GDB has been installed successfully, it should be noted that the debug Golang minimum need GDB version is greater than 7.1. (I installed the mingw-w64 gdb7.8.1)
12. In ST2 click Preferences > Gogdb > Settings–default
Note: The Workingdir is set to%gopath%\bin,commandline./The following section depends on the debug process name.
13. When configured, enter go Install-gcflags "-n-l" in the ctrl+b Popup command window to compile the binary executable, add a breakpoint to Main.go, and then press F5 to start debugging, all the configuration items in this article have been completed. Let's start a Golang tour!
Thank you!
Reference:
1.) THE-WAY-TO-GO_ZH_CN
2.) Sublime Text 2 to build the Go development environment
3.) How to configure Golang develop environment with debug and unit test debug
4.) Go Language programming
Golang configuration of the sublime text development debugging environment under Windows