From 3562cbae2502464d6cae52e95ca2a4191a753ff7 Mon Sep 17 00:00:00 2001 From: Ajian Date: Mon, 29 Oct 2012 18:02:27 +0800 Subject: [PATCH] Update chapter5/photoweb.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 我所指出来的是书中不一样的地方,现在这段代码是正确的。这样看你书中的代码跟这里不是相同的一份。 --- chapter5/photoweb.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/chapter5/photoweb.go b/chapter5/photoweb.go index 30b2ad5..a3e886f 100644 --- a/chapter5/photoweb.go +++ b/chapter5/photoweb.go @@ -32,6 +32,7 @@ func init() { log.Println("Loading template:", templatePath) t := template.Must(template.ParseFiles(templatePath)) templates[templateName] = t +//我说的第2个问题,在书中这里是tmpl } } @@ -68,6 +69,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) { check(err) defer t.Close() _, err = io.Copy(t, f) +//在书中这里是:= check(err) http.Redirect(w, r, "/view?id="+filename, http.StatusFound) } @@ -102,7 +104,7 @@ func safeHandler(fn http.HandlerFunc) http.HandlerFunc { defer func() { if e, ok := recover().(error); ok { http.Error(w, e.Error(), http.StatusInternalServerError) - +//书中这里是 http.Error(w,err.Error(),http.StatusInternalServerError)所以我说e这个变量可以变化 // 或者输出自定义的 50x 错误页面 // w.WriteHeader(http.StatusInternalServerError) // renderHtml(w, "error", e.Error())