func handleBookmarklet(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) u := user.Current(c) if u == nil { output(c, w, "bookmarklet_not_loggedin") return } url := r.FormValue("url") title := r.FormValue("title") tagString := r.FormValue("tags") tags := strings.Split(tagString, ",") bm := bookmarks.NewBookmark(u, url, title, tags) _, err := bm.Save(c) if err != nil { http.Error(w, err.String(), http.StatusInternalServerError) return } output(c, w, "bookmarklet_save", map[string]interface{}{ "url": url, "title": title, "tags": tags, }) }
func handleCreate(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) u := user.Current(c) if u == nil { return } r.ParseForm() url := r.FormValue("url") title := r.FormValue("title") tagString := r.FormValue("tags") if url == "" { output(c, w, "create") return } tags := strings.Split(tagString, ",") bm := bookmarks.NewBookmark(u, url, title, tags) _, err := bm.Save(c) if err != nil { http.Error(w, err.String(), http.StatusInternalServerError) return } w.Header().Set("Location", rootURL(c)) w.WriteHeader(http.StatusFound) return }
func handleDelete(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) u := user.Current(c) if u == nil { return } url := r.FormValue("url") bm := bookmarks.NewBookmark(u, url, "", []string{}) _, err := bm.Delete(c) if err != nil { http.Error(w, err.String(), http.StatusInternalServerError) return } w.Header().Set("Location", rootURL(c)) w.WriteHeader(http.StatusFound) return }