go study notes Guide

1、

Short declare variables

In the function, `: =` simple assignment statement in clear type of place, it may be used instead  var definition.

Each statement outside the function must begin with the keyword ( `var`,` func`, etc.), `: =` structure can not be used outside the function

 

2、

basic type

Go basic types are Basic types

BOOL 

String 

int Int32 int8 int16 int64 
uint uint8 uint16 uint32 UInt64 UIntPtr 

byte // alias for uint8 

rune // int32 alias 
     // represent a Unicode code 

float32 float64 

complex64 complex128

 

3、

Type Conversion

Expression  T(v) value  v is converted to type `T`.

Something about the value of the conversion:

were int = 42 
was f float64 = float64 (i) 
were u uint = uint (f)

Or, more simple form:

i := 42
f := float64(i)
u := uint(f)

Go and C are different from the needs of the project at the explicit conversion between different types of assignments.

 

4、

constant

Definition and similar variables constant, but the use of  const keywords.

Constant value can be a character, string, Boolean, or numeric type.

Constants can not use the  := syntax definition.

 

5, switch statements

  the: = runtime.GOOS  

switch os {

  case "darwin":
    fmt.Println("OS X.")
  case "linux":
    fmt.Println("Linux.")
  default:
    fmt.Printf("%s.", os)
}

No terms of the switch

`Switch with no conditions as switch true`.

This configuration makes it possible to form a clearer preparation of long chain if-then-else.

 

6、

defer

defer the execution statement will be delayed until the upper function function returns.

Delayed call parameters will immediately generate, but return to the previous function in the upper function will not be called.

defer 栈

Function call delay is pushed on a stack. When the function returns, calls the function calls are delayed in the order of LIFO.

 

7、

  1. Regardless of your method of receiver type or non-pointer is a pointer type, can all be carried out by the pointer / non-pointer type of call, the compiler will help you to do the conversion.
  2. In a statement the receiver is a method of pointer and non-pointer type, you need to consider two aspects of the interior, the first aspect is the object itself is not particularly large, if the pointer variable declared as non-call will produce a copy; the first two aspects is that if you use a pointer type as a receiver, then you must pay attention to this type of pointer is always pointing to a memory address, even if you have a copy of them. Lv familiar with C or C of the people here should soon be able to understand.

Guess you like

Origin www.cnblogs.com/wsw-seu/p/11260063.html