修改格式 (#371)

* 修改格式

* 二次优化
This commit is contained in:
eZio Pan
2017-06-14 20:07:01 +08:00
committed by 无闻
parent 2851ff5ae6
commit 0c841b3ac1

View File

@@ -60,25 +60,33 @@ func f() {
关键字 defer 允许我们进行一些函数执行完成后的收尾工作,例如: 关键字 defer 允许我们进行一些函数执行完成后的收尾工作,例如:
1. 关闭文件流 1. 关闭文件流 (详见 [第 12.2 节](12.2.md)
// open a file ```go
defer file.Close() (详见第 12.2 节) // open a file
defer file.Close()
```
2. 解锁一个加锁的资源 2. 解锁一个加锁的资源 (详见 [第 9.3 节](09.3.md)
mu.Lock() ```go
defer mu.Unlock() (详见第 9.3 节) mu.Lock()
defer mu.Unlock()
```
3. 打印最终报告 3. 打印最终报告
printHeader() ```go
defer printFooter() printHeader()
defer printFooter()
```
4. 关闭数据库链接 4. 关闭数据库链接
// open a database connection ```go
defer disconnectFromDB() // open a database connection
defer disconnectFromDB()
```
合理使用 defer 语句能够使得代码更加简洁。 合理使用 defer 语句能够使得代码更加简洁。