Пример #1
0
// 删除指定新闻
func (this *NewsController) Delete(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Admin News Delete")
	if r.Method != "POST" {
		this.Err400(w, r, "Error", "Error Method to Delete news")
		return
	}

	this.Init(w, r)

	if this.Privilege != config.PrivilegeAD {
		this.Err400(w, r, "Warning", "Error Privilege to Delete news")
		return
	}

	args := this.ParseURL(r.URL.String())
	nid, err := strconv.Atoi(args["nid"])
	if err != nil {
		http.Error(w, "args error", 400)
		return
	}

	newsModel := model.NewsModel{}
	err = newsModel.Delete(nid)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}

	w.WriteHeader(200)
}
Пример #2
0
// 删除指定新闻
//@URL: /admin/news/(\d+)/ @method: DELETE
func (nc *AdminNews) Delete(Nid string) {
	restweb.Logger.Debug("Admin News Delete")

	if nc.Privilege != config.PrivilegeAD {
		nc.Err400("Warning", "Error Privilege to Delete news")
		return
	}

	nid, err := strconv.Atoi(Nid)
	if err != nil {
		nc.Error("args error", 400)
		return
	}

	newsModel := model.NewsModel{}
	err = newsModel.Delete(nid)
	if err != nil {
		nc.Error(err.Error(), 400)
		return
	}

	nc.W.WriteHeader(200)
}