go-Basic Learning Summary

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

1, background: Go is a strongly typed language, because the developer thinks c#,java,c++ is too heavy. And c is too old, developers want to imitate C developed a near the bottom of the third-generation language. In the context of the prevailing multi-core era, go follows the trend and insists on simple principles to create the go

2, basic syntax:

Basic Data type: int16 int32 int64 float32 float64 sring Complex

3, define

Data definition:

Int Int[] Slice
var i int;i=0;
var i int = 0 '
var i,j int=0,0;
I:=0
i,j:=0,0
var arr =[]int{0,1}
var arr =[10]int;
Arr:=[10]int
Arr:=[...] {0,1,2,3}
Pointer to array
This anti-human design, personal expression to adapt for a period of time

4, Key words

4.1:goto

4.2: No while only for

4.3:if no parentheses behind the curly braces

4.4:range Implementation Traversal

5, function

5.1: Affirm func [(T *t)] MyFunc (a arguement) (b returnvalue) {

}

5.2: Multiple values can be returned

6,slice

The essence of 6.1,slice is a pointer to an array. He made up the fixed length of the array.

6.2, affirm

var s = make ([]int,5,6) three parameters for type, length, capacity

var s=[]int{0,1,2,3,4} Create Slice

var s1=s[2:]

6.3, add, delete, traverse

Append for Range

7,map

7.1 Map is a dictionary one-to-one key-value pair

7.2 Declaration

Colors: = map[string]string{}
colors["Red"] = "#da1337"

var colors =make (map[string]string)

7.3 Delete Traverse judgment weight

Delete (Map,key)

For range

Value, Isexit = map["Red"]

If value!= "" {};if isexit{}

8,chanle

8.1 Pipes. Super Mary inside that pipeline, shared resources exist inside to use when out of the inside to take out, so that others can not use. Put it back when you're done. So that people can use it.

8.2 Disclaimer:

C: =make (int chan)

C: =make (int chan 3) back to buffer length

9,go Ctrip

9.1, is the thread



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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.