Go basic Knowledge system

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

The whole knowledge system revolves around the logical structure, is the process oriented, the object is object-oriented. So a knowledge system can start with fields, functions, structures, and the logical structure of detailed coding, that is, process-oriented deepening. Then there are pointers, exception mechanisms, IO, concurrency, and so on. With the basic architecture is the network, background and other advanced features.

It is important to note that the go language is basically designed to be as simple as possible, simplifying, and, of course, partially odd, but also because there are other reasons for consideration.


Field:

1. Data manipulation. Includes definitions of basic data types and operations, calculations, slices, and so on. Note the pointer.

2. The field can be an anonymous field in the struct.

3.array,map,slice is a high-level structure. The array is a slice, and the slice is processed for the array. Map is a map. Use range traversal.

4. Parallel assignment i,j=i+1,j+1. This is generally used in the IF.

Structure:

1. Definition of structure. In go, a class is a struct and a function overlay. The structure is the "structure" in the algorithm and structure.

2.type is used to redefine data, define structs, interfaces.

3.go is closer to theory, so in Go class, method, variable, called struct, function, field.



Function:

1. Definition of function. In Go are functions, and functions that belong to structs can be called methods.

2. Functions have anonymous functions.

3.func FuncName (input1 type1, Input2 type2) (output1 type1, Output2 type2) {
Here is the process logic code
Return multiple values
return value1, value2
}

Fields and return fields can be simplified. such as Input1,input2 type. This is the fact that if there is no current, look behind.

4. Note the variable parameter func (arg...int)



Process Control:

1.if references the for, which can be used, separated by semicolons, preceded by a variable declaration.

The 2.switch case comes with a break, and you want to use Fallthrough to perform down. The switch-followed statement is true if it is not added.

3.for format If a semicolon is omitted, then it is equivalent to while. The for range can be used to read slice and map data.

4.goto is a jump statement.



Pointer:

1.string,slice,map is a pointer-based mechanism that can be passed directly, without the need to take the address to pass the pointer operation. But note that if the length of the slice changes, you still need to take the address to pass the pointer.

2. The use of struct pointer functions requires attention.



An expression:

1.go does not support ternary expressions. In other words, a N:=expr?truev:falsev cannot be used here.



Abnormal:

In 1.go, exception handling is used in conjunction with panic (), recover (), defer. Panic throws an abnormal interrupt, and if you want to reply, you can use recover recovery in defer. But go, try to use less exception handling.



Io:

Use make () in 1.go to create slices, maps, aromas. Returns the object, and new () returns a pointer.

The 2.chan is divided into two types: buffered and unbuffered.

3.chan as the IO channel for thread-piece communication.

4. Select,case,default combination Chan is often used for operation.



Concurrent:

1. Concurrency is mainly multi-threaded and commonly used auxiliary classes.

2. Concurrent content typically consists of:

(1) Initialization of the thread. The implementation of the thread is go xxx, this process is called gorutine.

(2) The communication of the thread. Communication through the channel. Note that the channel itself is a lock function and is often used as the simplest and most commonly used lock.

(3) The operation of the thread for the resource. This is mainly the concept of synchronous asynchronous, blocking and non-blocking.

The key to synchronous asynchrony is mutual exclusion, and the key to blocking and non-blocking is locking. But the two are actually close.

So the mutex is often present. Sync is often used here. Mutext.lock () implements mutual exclusion locks. Use lock. Lock () to implement locks. Runtime modules are often used to run some operations, to help the thread implement the time slice, the thread exits and so on. The atomic module is an atomic operation. Some of the other classes and functions are extensions based on these concepts.

(4) Concurrent architecture?





Parallel:?










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.