This is a creation in Article, where the information may have evolved or changed.
A preface
The main ways to build a go development environment are:
- Goeclipse
- Sublime text + gosublime + gocode
- Liteide
The first, the slower, the third, a software to be installed; The second method is recommended.
Two steps
- Install go environment, configure Goroot and Gopath, add path variable
Install package controll ( crtrl + 反引号
enter command)
Enter the following and press ENTER (different versions of Sublime, which seem to differ).
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'
Install Gosublime pakcage ( ctrl + shift + p
enter Package manager)
Enter install
a carriage return and enter a dialog box to install Pakcage
Enter GoSublime
return
Install Gocode (Language auto-complete daemon) (using go get
the GIT environment installed)
go get -u github.com/nsf/gocode
Get project file
go install github.com/nsf/gocode
Compile the project file to get the executable file
Configure Gosublime to use it
Preferences ==> Package Settings ==> gosublime ==> settings-default
Add the file's
"env":{},
Switch
"env":{ "path":"E:\\GoRepo\\gocode\\bin" },
Among them, the E:\\GoRepo
author holds the total directory of the downloaded Go Library, E:\GoRepo\gocode\bin ' contains the Gocode executable file.
- Writing a Hello file
ctrl + b
Switch to side bar display status
[ E:/workspaces/golang/hello/ ] go build hello.go[ E:/workspaces/golang/hello/ ] hello
The first go project of the three
For example, E:\\workspaces\\golang
create a new Web project in:
$ cd /e/workspaces/golang$ mkdir myweb$ cd myweb$ mkdir src$ mkdir bin$ cd src$ mkdir server // 弄个server包$ // 在server包下创建server.go文件$ cd ../bin$ go build server // 编译server.go文件(如果server.go引入了其它包的文件,则编译其它包)$ ./server // 运行server
* * NOTE: * * In order to build this project, "E:\workspaces\golang\myweb" must be added to the GOPATH environment variable.
When developing under Sublime, you can Preferences ==> package settings ==> gosublime ==> Settings-user to add the following to the file:
{"env": {"GOPATH":"E:\\workspaces\\golang\\myweb"}}