Installation and configuration of the go language, and package references

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

1. Download and install

First of all, you can go to the official website to download http://golang.org/dl/

If you do not understand the official website, you can download here: Http://golangtc.com/download, here also provides the download of Baidu Cloud address:

If you need to download the MSI file further installation, the installation process is very simple;

If you download the zip file, you can use it to unzip it directly.

2. Configuration

Open environment variables

And then

Immediately after editing path

Open cmd command line, enter: Go

If the display

It means success.

And then we can program, let's write a "Hello World":

I'm using the sublime Text compiler,

Then run:


Or

Well, we succeeded in outputting the Hello world!

3. Package References (The following content is from: http://www.cnblogs.com/sunshiming/p/4928493.html)

A. The simplest way to introduce a package is to introduce the package directly, for example:

Import "FMT"

Import "OS"

B. The package can also be introduced in the following way, and written in parentheses:

    InPort (

"FMT"

"OS"

)

In this way, you can introduce a system package or a third-party package, and the following highlights how to introduce custom packages and functions:

In general, we put the main program under the Mian folder of SRC (the main program contains the main function, and the package name of the main program is written as the bundle main), and the other modules are placed in the appropriate folder, for example

The main function in the Main.go file, the main function name can also be other, but must contain the main function. In go programming, how do you introduce your own modules, such as how to invoke Add.go, Subtract.go, or multiply.go files in Main.go.

Add.go and Subtract.go are under the Cal folder, so the packages for both programs are named CAL (Package cal), Multiply.go under the Multi folder, so the package name of the program is multi (packages multi). If the Mian function is to invoke a function in Add.go or SUBTRACT.GO, the package "Cal" (import "cal") must be introduced. To invoke a function in Multiply.go, it is necessary to introduce the package "multi", if we write the import "multi" directly in the program, the compiler will prompt us can not find the "multi". Since our "Multi" package is under the package "Cal", we are going to write the package name in full "Cal/multi", and we can invoke the functions in each file.

If the first letter of the function name is capitalized in go, it means that the function is public and can be called by other programs, and if the first letter is lowercase, the function is private, so we can only invoke public functions in Add.go, Subtract.go, or Multiply.go. Specific calls such as:

  

Add.go

  

Subtract.go

  

Multiply.go

  

Last Note: The file name can be inconsistent with the package name, but the package name used in the files must be the same as the package name.

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.