func handleViewPage(w http.ResponseWriter, r *http.Request) { noteId := r.URL.Path[3:] // Guard ourselves again matching /n/gibberish (check for uuid length) if len(noteId) != 36 { w.WriteHeader(404) w.Write([]byte("404 - Page not found")) return } note, err := data.GetNote(DB(), noteId) if err == sql.ErrNoRows { w.WriteHeader(404) w.Write([]byte("404 - Page not found")) } else if err != nil { w.WriteHeader(500) w.Write([]byte("500 - Error fetching note")) log.Fatal(err) } else { contents, err := RenderViewPage(Page{ Notes: data.MustGetAllNotes(DB()), Id: note.Id, Title: note.Title, Body: note.Body, PostbackURL: "/n/" + note.Id, }) mst.MustNotErr(err) w.Write(contents) } }
func handleEditPage(w http.ResponseWriter, r *http.Request) { noteId := r.URL.Path[3 : len(r.URL.Path)-5] note, err := data.GetNote(DB(), noteId) if err == sql.ErrNoRows { w.WriteHeader(404) w.Write([]byte("404 - Page not found")) } else if err != nil { w.WriteHeader(500) w.Write([]byte("500 - Error fetching note")) log.Fatal(err) } else { contents, err := RenderEditPage(Page{ Notes: data.MustGetAllNotes(DB()), Id: note.Id, Title: note.Title, Body: note.Body, PostbackURL: "/n/" + note.Id + "/edit", }) mst.MustNotErr(err) w.Write(contents) } }