mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2025-12-20 12:44:20 +08:00
第1章,局部字词修订。
This commit is contained in:
@@ -112,14 +112,17 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
```
|
||||
GET /?q=query HTTP/1.1
|
||||
Header["Accept-Encoding"] = ["gzip, deflate, sdch"] Header["Accept-Language"] = ["en-US,en;q=0.8"]
|
||||
Header["Accept-Encoding"] = ["gzip, deflate, sdch"]
|
||||
Header["Accept-Language"] = ["en-US,en;q=0.8"]
|
||||
Header["Connection"] = ["keep-alive"]
|
||||
Header["Accept"] = ["text/html,application/xhtml+xml,application/xml;..."] Header["User-Agent"] = ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5)..."] Host = "localhost:8000"
|
||||
Header["Accept"] = ["text/html,application/xhtml+xml,application/xml;..."]
|
||||
Header["User-Agent"] = ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5)..."]
|
||||
Host = "localhost:8000"
|
||||
RemoteAddr = "127.0.0.1:59911"
|
||||
Form["q"] = ["query"]
|
||||
```
|
||||
|
||||
可以看到这里的ParseForm被嵌套在了if语句中。Go语言允许这样的一个简单的语句结果作为循环的变量声明出现在if语句的最前面,这一点对错误处理很有用处。我们还可以像下面这样写(当然看起来就长了一些):
|
||||
可以看到这里的ParseForm被嵌套在了if语句中。Go语言允许这样的一个简单的语句结果作为局部的变量声明出现在if语句的最前面,这一点对错误处理很有用处。我们还可以像下面这样写(当然看起来就长了一些):
|
||||
|
||||
```go
|
||||
err := r.ParseForm()
|
||||
|
||||
Reference in New Issue
Block a user