func editHandler(w http.ResponseWriter, r *http.Request) { title := remux.Vars(r)[0] p, err := loadPage(title) if err != nil { p = &Page{Title: title} } renderTemplate(w, "edit.html", p) }
func viewHandler(w http.ResponseWriter, r *http.Request) { title := remux.Vars(r)[0] p, err := loadPage(title) if err != nil { http.Redirect(w, r, "/edit/"+title, http.StatusFound) return } renderTemplate(w, "view.html", p) }
func saveHandler(w http.ResponseWriter, r *http.Request) { title := remux.Vars(r)[0] body := r.FormValue("body") p := &Page{Title: title, Body: []byte(body)} err := p.save() if err != nil { log.Println(err.Error()) http.Error(w, http.StatusText(500), 500) return } http.Redirect(w, r, "/view/"+title, http.StatusFound) }