func CreatePage(db *sql.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { page := models.Page{ Title: r.FormValue("title"), Content: r.FormValue("content"), } err := page.Save(db) if err != nil { log.Fatal(err) } http.Redirect(w, r, "/", http.StatusFound) } }
func SavePage(db *sql.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { id, err := strconv.Atoi(r.URL.Query().Get("id")) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } page := models.Page{ ID: id, Title: r.FormValue("title"), Content: r.FormValue("content"), } err = page.Save(db) if err != nil { log.Fatal(err) } http.Redirect(w, r, fmt.Sprintf("/show?id=%d", id), http.StatusFound) } }