The 1th chapter, the first language of Go
1.1 A Brief history of languages
1.2 Language Features
1.2.1 Automatic garbage collection
1.2.2 Richer built-in types
1.2.3 function multiple return value
1.2.4 Error Handling
1.2.5 Anonymous functions and closures
1.2.6 Types and Interfaces
1.2.7 Concurrent Programming
Package Mainimport"FMT"func sum (values []int, Resultchan Chanint) {sum:=0 for_,value: =range Values {sum+=Value} Resultchan<-Sum}func Main () {values:= []int{1,2,3,4,5,6,7,8,9,Ten} Resultchan:= Make (chanint,2) Go sum (Values[:len (values)/2],resultchan) Go sum (Values[len (values)/2:],resultchan) sum1,sum2:= <-resultchan,<-Resultchan FMT. Println ("Result:", sum1,sum2,sum1+sum2)}
Paracalc
1.2.8 Reflex
Package Mainimport ("FMT" "reflect") Type Birdstruct{Namestringlifeexpectanceint}func (b*Bird) Fly () {fmt. Println ("I am Flying ...")}func Main () {sparrow:= &bird{"Sparrow",3} s:=reflect. ValueOf (Sparrow). Elem () Typeoft:=S.type () forI: =0; I < S.numfield (); i++{f:=S.field (i) fmt. Printf ("%d:%s%s =%v\n", I,typeoft.field (i). Name,f.type (), F.interface ())}}
reflect
1.2.9 language interactivity
Package Main /* #include <stdio.h> */ "C""unsafe"func Main () { CStr:= c.cstring ("hello,world") c.puts (CStr) C.free ( unsafe. Pointer (CStr))}
Cprint
1.3 First Go Program
" FMT " Func Main () { fmt. Println ("hello,world")}
Hello World
1.3.1 Code Interpretation
1.3.2 Compilation Environment Preparation
$go version
1.3.3 Compiling the program
1.4 Development Tool Selection
1.5 Project Management
Package Mainimport"OS"Import"FMT"Import"Simplemath"Import"StrConv"varUsage =func () {fmt. Println ("usage:calc command [arguments] ...") fmt. Println ("\nthe commands are:\n\tadd\taddition of the Values.\n\tsqrt\tsquareRoot of a non-negative value.")}func Main () {args:=OS. Argsifargs = = Nil | | Len (args) <2{Usage ()return } Switchargs[0] { Case "Add": ifLen (args)! =3{fmt. Println ("usage:cacl Add <integer1><integer2>") return} V1,ERR1:= StrConv. Atoi (args[1]) V2,ERR2:= StrConv. Atoi (args[2]) ifErr1! = Nil | | Err2! =Nil {fmt. Println ("Usage:calc add<integer1><integer2>") return} RET:=Simplemath. ADD (V1,V2) fmt. Println ("Result:", ret) Case "sqrt": ifLen (args)! =2{fmt. Println ("Usage:calc sqrt <integer>") return} v,err:= StrConv. Atoi (args[1]) ifErr! =Nil {fmt. Println ("Usage:calc sqrt <integer>") return} RET:=Simplemath. Sqrt (v) fmt. Println ("Result:", ret)default: Usage ()}}
CALCL
int int int { return A + B}
Add
" Testing " *testing. T) { r:= Add (1,2) if3 { T.errorf ( " Add (failed). Got%d,expected 3. " , R) }}
add_test
" Math " intint { V:= Math. Sqrt (Float64 (i)) returnint(v)}
sqrt
" Testing " *testing. T) { V:= Sqrt (+) if4 { T.errorf (" Sqrt (failed). Got%v,expected 4. " , V) }}
sqrt_test
1.6 Problem Tracking and debugging
1.6.1 Print Log
1.6.2 GDB Debugging
1.7 How to ask for help
1.7.1 Mailing List
1.7.2 Website Resources
1.8 Summary
2nd Chapter Sequential Programming
2.1 Variables
2.1.1 Variable declaration
2.1.2 Variable Initialization
2.1.3 Variable Assignment
2.1.4 Anonymous variables
2.2 Constants
2.2.1 Literal constants
2.2.2 Constant definition
2.2.3 Pre-defined constants
2.2.4 Enumeration
2.3 Types
2.3.1 Boolean type
2.3.2 Integral type
2.3.3 Floating Point type
2.3.4 plural type
2.3.5 string
2.3.6 Character types
2.3.7 Array
2.3.8 array slices
2.3.9 Map
2.4 Process Control
2.4.1 Conditional statements
2.4.2 SELECT statement
2.4.3 Loop Statements
2.4.4 Jump Statement
2.5 functions
2.5.1 function definition
2.5.2 Function call
2.5.3 Indeterminate parameters
2.5.4 Multiple return values
2.6 Error Handling
2.6.1 Error interface
2.6.2 defer
2.6.3 Panic () and recover ()
2.7 Complete Example
2.7.1 Program Structure
2.7.2 Main Program
2.7.3 Algorithm Implementation
2.7.4 Main Program
2.7.5 Construction and execution
2.8 Summary
The 3rd Chapter object-oriented programming
3.1 Type System
3.1.1 Adding a method to a type
3.1.2 Value semantics and referential semantics
3.1.3 Structural Body
3.2 Initialization
3.3 Anonymous Combinations
3.4 Visibility
3.5 interface
3.5.1 Interface for other languages
3.5.2 Non-intrusive interface
3.5.3 Interface Assignment
3.5.4 Interface Query
3.5.5 type Query
3.5.6 Interface Combination
3.5.7 any type
3.6 Complete Example
3.6.1 Music Library
3.6.2 Music Playback
3.6.3 Main Program
3.6.4 Build Run
3.6.5 Legacy Issues
3.7 Summary
4th Chapter Concurrent Programming
4.1 Concurrency Basics
4.2 Co-process
4.3 goroutine
4.4 Concurrent Communication
4.5 Channel
4.5.1 Basic Syntax
4.5.2 Select
4.5.3 buffering mechanism
4.5.4 Timeout mechanism
Transmission of 4.5.5 Channel
4.5.6 Unidirectional Channel
4.5.7 Close Channel
4.6 Multi-core parallelization
4.7 Sell time slices
4.8 Synchronization
4.8.1 Sync Lock
4.8.2 Global Uniqueness Operations
4.9 Complete Example
4.9.1 Simple IPC Framework
4.9.2 Central server
4.9.3 Main Program
4.9.4 Running Small Programs
4.10 Summary
The 5th Chapter Network programming
5.1 Socket Programming
5.1.1 Dial () function
5.1.2 ICMP sample Program
5.1.3 TCP Sample Program
5.1.4 Richer network communication
5.2 HTTP Programming
5.2.1 HTTP Client
5.2.2 HTTP Service side
5.3 RPC Programming
RPC support and processing in the 5.3.1 go language
5.3.2 Gob Introduction
5.3.3 designed an elegant RPC interface
5.4 JSON processing
5.4.1 Encoding to JSON format
5.4.2 Decoding JSON data
5.4.3 decoding JSON data for unknown structures
Streaming read-write for 5.4.4 JSON
5.5 Website Development
5.5.1 The simplest website program
5.5.2 Net/http Package Introduction
5.5.3 to develop a simple photo album website
5.6 Summary
6th Chapter Safety Programming
6.1 Data encryption
6.2 Digital Signatures
6.3 Digital Certificates
6.4 PKI System
6.5 The hash function of the Go language
6.6 Encrypted Channel
6.6.1 Encrypted communication flow
6.6.2 Web server that supports HTTPS
6.6.3 file servers that support HTTPS
6.6.4 SSL/TLS-based Echo program
6.7 Summary
The 7th Chapter Project management
7.1 Go command line tool
7.2 Code Style
7.2.1 Mandatory Coding Specification
7.2.2 non-mandatory coding style suggestions
7.3 Remote Import Support
7.4 Engineering Organization
7.4.1 Gopath
7.4.2 directory Structure
7.5 Document Management
7.6 Engineering Construction
7.7 Cross-platform development
7.7.1 Cross-compiling
7.7.2 Android Support
7.8 Unit Test
7.9 Packing and distributing
7.10 Summary
8th Chapter Development Tools
8.1 Select Development Tools
8.2 gedit
8.2.1 Syntax highlighting
8.2.2 Compilation Environment
8.3 Vim
8.4 Eclipse
8.5 notepad++
8.5.1 Syntax highlighting
8.5.2 Compilation Environment
8.6 Litelide
8.7 Summary
9th Chapter Advanced Topics
9.1 Reflection
9.1.1 Basic Concepts
9.1.2 Basic Usage
9.1.3 reflection operations on structures
9.2 Language interactivity
9.2.1 Type Mapping
9.2.2 String Mappings
9.2.3 C Program
9.2.4 function call
9.2.5 Compiling CGO
9.3 Link Symbols
Mechanism of 9.4 goroutine
9.4.1 Ctrip
9.4.2 Ctrip's C language implementation
9.4.3 Libraries Overview
9.4.4 Tasks
9.4.5 Task Scheduling
9.4.6 Context Switch
9.4.7 Communication mechanism
9.5 Interface Mechanism
9.5.1 type assignment to interface
9.5.2 interface Query
9.5.3 Interface Assignment
Go Language programming