Initialization
- Constants
用iota創(chuàng)建枚舉常量 - Variables
- The init function
Methods
- Pointers vs. Values
The rule about pointers vs. values for receivers is that value methods can be invoked on pointers and values, but pointer methods can only be invoked on pointers. This is because pointer methods can modify the receiver; invoking them on a copy of the value would cause those modifications to be discarded.
Interfaces and other types
- Interfaces
- Conversions
方便排序的能夠做強(qiáng)制轉(zhuǎn)換的sort.IntSlice()
- Interface conversions and type assertions
類型斷言用來實(shí)現(xiàn)類似動(dòng)態(tài)類型轉(zhuǎn)換的功能 - Generality
返回接口而不是具體實(shí)現(xiàn),可以清晰地表明行為比實(shí)現(xiàn)重要的設(shè)計(jì)理念。 - Interfaces and methods
The blank identifier
- The blank identifier in multiple assignment
- Unused imports and variables
- Import for side effect
適用于只引用包冠桃,利用它的副作用而不使用其中名字的情況 - Interface checks
var _ json.Marshaler = (*RawMessage)(nil) // Check if RawMessage implements json.Marshaler in compile time
Embedding
通過嵌入得到實(shí)現(xiàn)復(fù)用板乙。
Concurrency
- Share by communicating
Do not communicate by sharing memory; instead, share memory by communicating.
- Goroutines
相同地址空間,輕量級(jí),在多個(gè)系統(tǒng)線程中復(fù)用。 - Channels
- Channels of channels
- Parallelization
- A leaky buffer
Errors
- Panic
- Recover
A call to recover stops the unwinding and returns the argument passed to panic. Because the only code that runs while unwinding is inside deferred functions, recover is only useful inside deferred functions.
recover
在deferred
函數(shù)中與普通函數(shù)中的表現(xiàn)是不同的,在普通函數(shù)中總是返回nil
弄匕,這就允許deferred
函數(shù)可以正常調(diào)用其他庫函數(shù)。