Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion chapter5/photoweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func init() {
log.Println("Loading template:", templatePath)
t := template.Must(template.ParseFiles(templatePath))
templates[templateName] = t
//我说的第2个问题,在书中这里是tmpl
}
}

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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())
Expand Down