Go Language learning Note (i): Build a Go development environment under Windows

Source: Internet
Author: User
Tags install go git shell gocode

The recent sudden interest in the go language was mainly due to some unpleasant problems when using python and then to go. Go is Google out of a dynamic language, syntax and C + + Close, performance is also very good, but also support compiled into EXE release, and do not rely on any virtual machine (in fact, packaged in EXE), how can this good language to miss? So it was a moment of rise and began to learn. Because I am still in the abnormal small white stage, so the article may inevitably some mistakes, welcome all kinds of correction.

Install Go

Go to the official website of the Go language: http://golang.org/, download the installation package for the corresponding platform. If it is x86 system can download i386, if it is x64 system, then the installation of AMD64 can be. In addition, there are two types of installation packages for the Go language under Windows: MSI and zip. Zip is free installation, decompression after the configuration of some environment variables can be used, MSI is the installation package version, the installation will be set up the corresponding environment variables. For convenience, I went down the MSI installation package on x64: Go1.1.2.windows-amd64.msi. After the installation package, the installation process is very simple, the next step in the end is good. Although the MSI will automatically configure some environment variables, but I still encountered some environment variable loss after installation, so after the installation of Go, we finally check whether some of the environment variables are normal. The main environment variables are as follows:

    • installation directory for Goroot:go
    • Gopath: The directory used to store the Go language package, which cannot be in the Go installation directory
    • Gobin:go binary Files directory, written%goroot%\bin is good
    • GOOS: Operating System
    • Goarch: Specifies the system environment, i386 represents the X86,AMD64 representation x64
    • Path: You need to add the%gobin% to the end of the path variable to make it easy to run go at the command line
    • We can also use go env to see the definition of all other environment variables

When the environment variables are configured properly, go is already installed. Now open the command line, run go, you should be able to see the following tips.

Hello go!

Now let's come to Hello World!

?
12345 package mainimport"fmt"func main() {    fmt.Println("Hello, World!")}

Save the above program to Hello.go and then execute it on the command line:

?
1 go run hello.go

tada! The result is out!

And the Go language can also compile the GO program directly into EXE, and then publish it, more convenient than Python (need to use py2exe), only need to run on the command line:

?
1 go build hello.go

You can see and execute the compiled exe.

In addition, we can also see that this hello.exe incredibly has 1.5M, this should be because go to the entire virtual machine is packaged into the exe inside the sake of, from the dependency on the EXE, he has completely no reliance on go, only a few system DLLs.

Ide

About the IDE everyone's preferences are different, you can use the more independent development environment liteide, also can be vs or eclipse, even notepad++, of course, not to mention vim and Emacs. Here, two more common ide:liteide and eclipse are introduced.

Liteide

Liteide is a very good integration of Go IDE, compile, debug, code completion, features are all. and free, open source, QT-based so it's also cross-platform. Its installation is very simple, from the official website (https://code.google.com/p/liteide/) download the corresponding platform installation package, and then extract to the specified directory.

Eclipse + goclipse

Eclipse is a very well-known IDE, so specifically how to install, I will not much to say, a brief introduction to the process.

    1. Download and install the latest JRE on the http://java.com/
    2. Download the latest eclipse from http://www.eclipse.org/and unzip it

Just downloaded eclipse is not support go, in order to allow it to support the go language, we need to install a plugin: Goclipse.
Project Address: https://code.google.com/p/goclipse/

The installation process is simple, just add a source in eclipse: http://goclipse.googlecode.com/svn/trunk/goclipse-update-site/, and then check Goclipse to install, such as.

After installation, restart Eclipse, and we can use eclipse to write the Go language program.

Gocode

When using Goclipse to write code, we will find that there is no code completion, in order to increase the code completion, we need to install Gocode. Liteide is not needed because it has built-in Gocode.

Gocode is the host on GitHub, using go write to do the Go language code completion of the project, the project address is: Https://github.com/nsf/gocode, there is a very detailed installation method. Because go has built-in tools like Package Manager, the installation is easy.

    1. Install git: Because Git is needed during installation, you need to install Msysgit or Cygwin first, and if you find this cumbersome, there is an easier way: Install GitHub for windows:http://windows.github.com/.
    2. Start the Git shell and run: Go get-u-ldflags-h=windowsgui github.com/nsf/gocode.
    3. Now look in the%gobin% directory and you will find Gocode.exe.

The next step is to configure Eclipse. Open windows->preferences, find Go->gocode tag, set the path of Gocode.exe.

Finish, and now write the code well.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.