Add delete paste handling

This commit is contained in:
Eliot Whalan 2016-06-19 16:59:19 +10:00
parent 451f93977b
commit 3c35238103
1 changed files with 21 additions and 4 deletions

23
main.go
View File

@ -104,9 +104,26 @@ func save(raw []byte) []string {
} }
func delHandler(w http.ResponseWriter, r *http.Request) { func delHandler(w http.ResponseWriter, r *http.Request) {
/* vars := mux.Vars(r) vars := mux.Vars(r)
paste := vars["pasteId"] paste := vars["pasteId"]
delkey := vars["delKey"] */ 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) { func saveHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
@ -164,7 +181,7 @@ func langHandler(w http.ResponseWriter, r *http.Request) {
paste := vars["pasteId"] paste := vars["pasteId"]
lang := vars["lang"] lang := vars["lang"]
s := getPaste(paste) 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) io.WriteString(w, highlight)
} }