// Del sub msg func del_sub(w http.ResponseWriter, r *http.Request, uu *user) { glog.Info("Del a sub.") sub := new(define.Sub) r.ParseForm() sub.Id = r.FormValue("id") if err := store.Manager.DelSub(sub.Id, uu.ID); err != nil { // Write the response glog.Errorf("Del sub in the web error:%v", err) badReaquest(w, `{"status":"fail"}`) } else { uu.isOK = true io.WriteString(w, `{"status":"success"}`) } }
// Add sub group func add_sub(w http.ResponseWriter, r *http.Request, uu *user) { glog.Info("Add a new sub.") sub := new(define.Sub) r.ParseForm() if s := r.FormValue("max"); s != "" { sub.Max, _ = strconv.Atoi(s) } if s := r.FormValue("type"); s != "" { sub.Typ, _ = strconv.Atoi(s) } // sub.Id = get_uuid() sub.Own = uu.ID if err := store.Manager.AddSub(sub); err != nil { glog.Errorf("Add new sub error(%v)", err) badReaquest(w, `{"status":"fail"}`) } else { glog.Info("Add sub ok.") uu.isOK = true io.WriteString(w, `{"sub_id":"`) io.WriteString(w, sub.Id) io.WriteString(w, `"}`) } }