From 4639fcf237c9ba232dd4d8d826731cc33d678e8e Mon Sep 17 00:00:00 2001 From: raylu Date: Sat, 6 Aug 2011 04:14:13 -0700 Subject: remove works --- main.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'main.go') diff --git a/main.go b/main.go index 73527a1..3220da6 100644 --- a/main.go +++ b/main.go @@ -136,6 +136,24 @@ func add(w http.ResponseWriter, r *http.Request) { w.Write([]byte("1")) } +func remove(w http.ResponseWriter, r *http.Request) { + q := r.URL.Query() + pid := getpid(q.Get("pid")) + if pid == -1 { + http.Error(w, "invalid pid", http.StatusInternalServerError) + return + } + + sql :="DELETE FROM `song` WHERE `pid` = %d AND yid = '%s'" + sql = fmt.Sprintf(sql, pid, q.Get("yid")) + err := db.Query(sql) + if err != nil { + http.Error(w, err.String(), http.StatusInternalServerError) + return + } + w.Write([]byte("1")) +} + func main() { templates = make(map[string]*template.Template) for _, path := range []string{"p"} { @@ -157,5 +175,10 @@ func main() { http.HandleFunc("/", home) http.HandleFunc("/p/", playlist) http.HandleFunc("/add/", add) - http.ListenAndServe(":8000", nil) + http.HandleFunc("/remove/", remove) + err = http.ListenAndServe(":8000", nil) + if err != nil { + fmt.Println(err) + os.Exit(1) + } } -- cgit v1.2.3