Learning Golang Language (1)

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

Thought for a long time to learn a new language, tangled for a long time, finally chose the go language. Get started today with Go language learning.

1. Download go

Http://www.golangtc.com/download

2. Download Liteide

Http://www.golangtc.com/download/liteide

3. Start programming

The first program to learn any programming language is Hello World. Create the Hello.go file in the Gopath directory and enter the following.

 
  
  
  1. package main
  2. import "FMT" // Introduction of FMT library
  3. func main () Span class= "PLN" > {
  4. Span class= "PLN" > FMT println ( "Hello world!"
  5. } /code>

Analyze This procedure line by row:
The first line is required. All files written in the Go language start with package <*> and must be the package main for running standalone files;
The second line indicates that the FMT package is added to main. Other packages, which are generally non-main, are called libraries,
The third line is the main function in the program. When the Go program executes, the function that is called first is the main function. This is inherited from C. Here is the function definition of the main function.
Line four calls the FMT package function to print the string to the screen. The string is wrapped by "" and can contain non-ASCII characters.

Note :

A standalone executable go program, the package main must appear, followed by the introduction of the various libraries, and then the individual functions, here must have a main function. The main function is the entry for the program.

Compile and run (using the win7 system, open cmd)

Use command: go build hello.go compile. The hello executable file for the. exe will be generated in the same directory.
Run:. hello exe
On-screen output: Hello World!
You can also use some parameters at compile time to reduce the size of the compiled file.
go build -ldflags "-s -w" hello.go




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.