A Note of Effective Go (Second H

2014-01-09  本文已影响0人  digiter

Initialization

Methods

Interfaces and other types

The blank identifier

var _ json.Marshaler = (*RawMessage)(nil) // Check if RawMessage implements json.Marshaler in compile time

Embedding

通过嵌入得到实现复用。

Concurrency

Do not communicate by sharing memory; instead, share memory by communicating.

Errors

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.

recoverdeferred函数中与普通函数中的表现是不同的,在普通函数中总是返回nil,这就允许deferred函数可以正常调用其他库函数。

A web server

上一篇下一篇

猜你喜欢

热点阅读