mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2024-12-26 14:56:21 +00:00
commit
db60748fa6
@ -41,7 +41,7 @@ The Go Programming Language
|
|||||||
$ ./title1 https://golang.org/doc/effective_go.html
|
$ ./title1 https://golang.org/doc/effective_go.html
|
||||||
Effective Go - The Go Programming Language
|
Effective Go - The Go Programming Language
|
||||||
$ ./title1 https://golang.org/doc/gopher/frontpage.png
|
$ ./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机制可以让事情变得简单。
|
resp.Body.close调用了多次,这是为了确保title在所有执行路径下(即使函数运行失败)都关闭了网络连接。随着函数变得复杂,需要处理的错误也变多,维护清理逻辑变得越来越困难。而Go语言独有的defer机制可以让事情变得简单。
|
||||||
|
Loading…
Reference in New Issue
Block a user