A small summary of Golang

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

Reprint: http://www.liguosong.com/2013/07/07/golang%E7%9A%84%E5%B0%8F%E6%80%BB%E7%BB%93/


VAR create variable

Const Create constant

Iota This keyword is used when declaring an enum, its default start value is 0, each call plus 1

Map is the concept of the dictionary in Python, its format for Map[keytype]valuetype map reading and setting is similar to slice, by key to operate, but only the slice index can only be ' int ' type, and map many types, can be an int, which can be a string

Make memory allocations for built-in types (map, slice, and channel)

New for various types of memory allocations

Goto jumps to a label that must be defined within the current function

The Func keyword func is used to declare a function funcname

Defer deferred execution code, similar to destructor

Panic interrupt the original control process

Recover function to resume interrupts

Import the package file

Some rules of Go programming

    • The variable that starts with the capital letter is exportable, which is the common variable that the other package can read, and the lowercase letter begins with a non-exportable, private variable.
    • A function that starts with a capital letter is the same as a public function with a common keyword in class, and a private function that starts with a secret keyword.

There are two reserved functions in go: the init function (which can be applied to all package) and the main function (can only be applied to package main). These two functions cannot have any parameters and return values when they are defined. Although it is possible to write any number of INIT functions in a package, it is strongly recommended that users write only one init function per file in a single document, whether for readability or later maintainability.

The GO program automatically calls Init () and main (), so you don't need to call these two functions anywhere. The INIT function in each package is optional, but the package main must contain a main function.


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.