This is a creation in Article, where the information may have evolved or changed.
Original link: http://blog.csdn.net/cnsword/article/details/17039073
Take a look at some of the knowledge of the go language, a lot of introductory tutorials on the Go language, and a tutorial on a point in-depth analysis, this article is not an introductory tutorial just to record some of the special points in the learning Golang process, of course these points are based on individuals (C,c++,python).
- Gopath is the path to the Go lookup package, Goroot is the Go installation directory, Gobin is the bin directory of Go Build
- Go is a strongly typed language, type declaration is behind
- Import. "FMT" open package content, import F "FMT" package Alias
- var p = fmt. Println defining function references
- Null is nil and NOT NULL or null
- No enumeration in Go
- Const, VAR, and import can be added () to handle multiple
- : = cannot declare global variables, only global variables can be declared by Var
- Rune = Uint,byte = int8
- A: = [...] Int{1, 2, 20:3}
- Switch type is more than C, the case can be any conditional statement after omitting the matching value
- Each file can have an init () function that is responsible for initialization, but cannot be explicitly called
- typedef can use type to implement
- function return value is behind
- Func can return multiple values, or it can be returned directly, and the return value is stored in the declared variable
- You can add func to any struct, including built-in types, but built-in types require type TypeName A_type into a local type
- The indeterminate parameters are implemented by the ... type, and are evaluated by the for rangs.
- If else for can be without parentheses, without a while statement
- Semicolons can be omitted
- Curly braces must be in the behavior
- Pointers are also used. Instead of->, the pointer is written so *int that the pointer cannot be calculated
- New is a function used to allocate memory to pointers, only 0 not initialized, new ([] int)
- Make can initialize slices, Map,chan. The return is not a pointer, is an initialized instance, make ([]int, 10, 100)
- No class, only struct, more interface, no concept of inheritance and virtual function
- No var before the struct variable
- There is no Func before the method in interface
- T interface{} defines an empty interface, an empty interface can correspond to any type and can be passed by T. (type) to the appropriate type, which applies only to NULL interfaces
- Interface generates a binding through InterfaceName (*struct)
- String is a built-in type
- No char type, using Byte, string directly
- The action string can be used with the strings package
- The panic corresponds to the catch,defer corresponding to the try, and the recovery operation requires Revcover
- Chan default is blocking non-blocking he oh sad select + default to implement, or with time timeout to achieve, close (channel) Close Chan
- Newtimer's time.c is performed only once, and Newticker's ticker.c can be looped, rang, with a for ticker. Stop () stops the loop
- Mutex, etc. in the sync bag
- Atomic operations in the Sync/atomic package
- The socket is in net package, net. Listen monitoring, net. Accept, net. Dail build LINK, Conn. Close closes
- Httpserver with Net/http bag
- System calls with OS package and Syscall package
- CGO Package for interaction with C
- Go own process to see the use of communication, the current go and other language programs between the process of communication needs to use C to achieve
- Include <stdio.h>
Import "C"
Import "unsafe"
To introduce CGO.
- CGO requested memory requires manual release of C.free (unsafe. Pointer (Char))
- cloud9 Building a Go language development environment reference: HTTP://WWW.OSCHINA.NET/TRANSLATE/GO-UP-AND-RUNNING-ON-CLOUD-9
Introduction can look at the Hao brother's: http://coolshell.cn/articles/8460.html http://coolshell.cn/articles/8489.html
PS: Because of the powerful worship of Docker, decided to explore its source code implementation, so first from go to learn.