Merge pull request #77 from caimaoy/patch-1

Update ch5-08.md
pull/79/head
Xargin 2019-12-24 19:13:20 +08:00 committed by GitHub
commit db60748fa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -41,7 +41,7 @@ The Go Programming Language
$ ./title1 https://golang.org/doc/effective_go.html
Effective Go - The Go Programming Language
$ ./title1 https://golang.org/doc/gopher/frontpage.png
title: https://golang.org/doc/gopher/frontpage.png has type image/png, not text/html
title1: https://golang.org/doc/gopher/frontpage.png has type image/png, not text/html
```
resp.Body.close调用了多次这是为了确保title在所有执行路径下即使函数运行失败都关闭了网络连接。随着函数变得复杂需要处理的错误也变多维护清理逻辑变得越来越困难。而Go语言独有的defer机制可以让事情变得简单。