Go language Environment Building (Go language learning notes)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

First, the Go language environment construction

Setting up the go language environment like building a Java environment, you first need to download the GO environment: https://code.google.com/p/go-windows/downloads/list (Hint: This site is Google's website, So in the domestic direct access is inaccessible, so need to fq out to visit the recommended use: Tornado VPN, can be used for free 1 hours, used to download things completely enough)

Select the appropriate environment for your machine version on the site to install, for the sake of convenience to choose the MSI suffix program does not have to configure environment variables, it automatically configures the environment variables

Second, the first go program Hello world!

Programmers learn languages almost all start with Hello World, so I will write my first go program Hello World.

Package main    Import "FMT"  func Main () {          fmt. Println ("Hello World")  }

Third, the Code interpretation

1.package main: Each Go program begins with the package declaration, which represents the packages to which the go code belongs. This and Java seems to be very type, but the difference is that the Java package name is created by the folder itself, and the package name here seems to have its own definition of the go language, this should be similar to the C language header file.

2.import "FMT": Used to import the package on which the program depends. This program uses the println () function, so you need to import the FMT package. This is in line with a lot of programming language ideas, but the format is different (PS: Must not contain the program does not need the package, or the program will not compile)

3.func Main () {

Fmt. Println ("Hello World")

}: All go functions (including the type member functions mentioned in object programming) start with the keyword func. A regular function definition consists of the following sections:

Func function name (argument list) (return value list) {
function body
}
A corresponding example is as follows:
Func Compute (value1 int, value2 float64) (Result float64, err error) {
function body
}
Go supports multiple return values. The example function above compute () returns two values, one called result and the other is err. Not all return values must be assigned a value. Return values that are not explicitly assigned when the function returns are set to the default values, such as result will be set to 0.0,err will be set to nil.


Iv. compiling and running Go program

This is similar to running Java programs manually: Start-"run-" input cmd--"Enter the full path of the Go Run program file (for example, enter the file name in the current directory) Eg:go run Helloworld.go

V. Eclipse Development Go Program

In the above project, we develop go program with the most original Notepad file for program development, in the actual process in order to improve development efficiency is often used to develop tools, and now we look at how to develop the Go program in Eclipse.

1. Install the Go plugin for eclipse

Select Help-->install New software.

Click Add ...

  

Name: Fill Eg:goplugin yourself

location:http://goclipse.googlecode.com/svn/trunk/goclipse-update-site/

  

Wait a minute. If the option is directly selected, then follow the prompts next>, as I have installed all the next display as Gray (PS: Fq before entering location, otherwise it will not appear this option)

After the installation is complete, Eclipse restarts, and then we just need to configure Goroot to write our go program in Eclipse.

  

Is this similar to configuring a JDK? So I'm not going to say much about that.

PS (This is the first time the Lord wrote a blog post, the purpose of this blog is to increase their own memory, later I forgot to look at the same time, but also to share to like me small white introduction of the program Ape, so hope the big God do not spray, direct bypass!!! )

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.