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())