From 3c3523810363b13635a164f3e18cb3adfe2cc3f5 Mon Sep 17 00:00:00 2001 From: Eliot Whalan Date: Sun, 19 Jun 2016 16:59:19 +1000 Subject: [PATCH] Add delete paste handling --- main.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index c9a74f0..d4af7ea 100644 --- a/main.go +++ b/main.go @@ -104,9 +104,26 @@ func save(raw []byte) []string { } func delHandler(w http.ResponseWriter, r *http.Request) { - /* vars := mux.Vars(r) - paste := vars["pasteId"] - delkey := vars["delKey"] */ + vars := mux.Vars(r) + paste := vars["pasteId"] + delkey := vars["delKey"] + + db, err := sql.Open("mysql", DATABASE) + check(err) + + stmt, err := db.Prepare("delete from pastebin where delkey=? id=?") + check(err) + + res, err := stmt.Exec(html.EscapeString(delkey), html.EscapeString(paste)) + check(err) + + affect, err := res.RowsAffected() + check(err) + + io.WriteString(w, string(affect)) + + db.Close() + } func saveHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) @@ -164,7 +181,7 @@ func langHandler(w http.ResponseWriter, r *http.Request) { paste := vars["pasteId"] lang := vars["lang"] s := getPaste(paste) - highlight := pygments.Highlight(html.UnescapeString(s), lang, "html", "full, style=autumn,linenos=True, lineanchors=True,anchorlinenos=True,", "utf-8") + highlight := pygments.Highlight(html.UnescapeString(s), html.EscapeString(lang), "html", "full, style=autumn,linenos=True, lineanchors=True,anchorlinenos=True,", "utf-8") io.WriteString(w, highlight) }