03 Go language features

First, the basic precautions

  1. escape character

. 1  \ T a tab, on behalf of a Tab
 2  \ newline n-
 3  \\ escape Representative \
 4 \ "     escape behalf " 
. 5 \ a R & lt carriage return, line front from the start of the current output, overwrites previous content, often with \ r \ n newline use

  2. Comment

1 //         line comment
 2 // Bank has been annotated
 3 / * * / block comments
 4 / * in this paragraph are annotated
 . 5 in this paragraph is annotated * /
 6  for fast line comments and annotations, annotation content is not Go the compiler performs
 7 Note: block comment can not be nested block comments

  3. The official standard API documentation

https://golang.org/ PKG
 . 1 ) the API (the Application Programming Interface, Application Programming Interface) programming interface is substantially Golang provided.
2 ) Go language provides a number of standard libraries, so google the company also provides a corresponding API documentation for these standard libraries, used to tell developers how to use these standard library, and methods contained in the standard library.
3) Golang Chinese online network standard library documentation: https://studygolang.com/pkgdoc

  4. naming

1 Code: source file must be in UTF-8 format, otherwise it will cause a compiler error.
2 Name: The camelCasing style (hump nomenclature), is not recommended to use an underscore.

Two, Go variable type

  Built-in type

  Value type:

. 1  BOOL Boolean type
 2 int (32 or 64 ), int8, Int16, Int32, Int64 integer type
 . 3 uint (32 or 64 ), uint8 (byte), UInt16, UInt32, UInt64 unsigned integer
 . 4  float32, float float64
 . 5  String String
 . 6  array of fixed-length array
 . 7 struct structure

  :( pointer types reference types)

. 1  Slice Slice
 2  Map map
 . 3  Chan duct
 . 4 interface Interface

Third, the built-in functions

  Go language has a number of built-in functions do not need to import can be used. Sometimes they may operate for different types, for example: len, cap and append, or to be used for system level operations, such as: panic. Therefore, they need direct support of the compiler.

. 1 the append - to append to the array elements, slice, the array is returned after modification, slice
 2 Close - mainly used Close Channel
 . 3 Delete - delete key corresponding to the value from the map
 . 4 panic - stop routine goroutine (panic and recover: used for error handling)
 . 5 Recover - allows the panic operation program definition goroutine
 . 6 imag - returns the real part of complex (complex, real imag: create and manipulate complex)
 . 7 real - Back complex the imaginary portion
 . 8 the make - to allocate memory to return themselves type (only applied Slice, Map, Channel)
 . 9 new new - to allocate memory, mainly used to assign a value type, such as int, struct. Returns a pointer to the Type
 10CAP - Capacity capacity is meant, for returning the maximum capacity of a certain type (only for sectioning and Map)
 . 11 Copy - the number of connections for replication and Slice, returned copy
 12 is len - to seek length, such as string, array, slice, map, channel, returns the length
 13 is  Print , the println - bottom printing function, it is recommended to use in the deployment environment package fmt

  init function

    go language initfunctions for packet (package)initialization, the function is an important feature of the language go.

  feature:

. 1 init function is a function used to make the package before the program performs the initialization, such as initializing variables bag
 2 for each package may have multiple functions init
 3 packets each source file may have multiple functions init
 4 same the order of execution of the init function a plurality of packets go no clear definition language (instructions)
 . 5 init function of different packet determines the execution order of an initialization function in accordance with the imported package dependencies
 . 6 init function can be called by other functions, but in the main before the function execution, it is called automatically

  main function    

A  default entry function (main function) Go language program: FUNC main ()
 2  function body wrapped with a pair of parentheses {}.
. 3  FUNC main () {
 . 4      // function body
 5 }

  Similarities and differences between the init function and main function

1  similarities:
 2      two functions in the definition can not have any parameters and return values, and automatically calls the Go.
3  differs:
 . 4      the init can be applied to any package, and may be repeated a plurality of definitions.
. 5      main function is only available in the main bag, and only a defined.

  The order of execution of two functions

1  performs two functions in the order:
 2    1 calls go to the same file init () order is from top to bottom.
3    2 is more of the same package in a different file by file name string "small to large" in order to call each file init () function.
4    3. For different package, if it is not interdependent, which calls init package in accordance with the main package "first call after import" sequence (), 
     if there is a dependency package, the first call in the first package being dependent the init (), and finally call the main function.

 

Guess you like

Origin www.cnblogs.com/a2534786642/p/11041907.html