Ejemplo n.º 1
0
// 通过uri删除文章
func DeleteArticle(id int64, uri string) (int64, error) {
	o := orm.NewOrm()
	o.Using("default")
	var art Article

	if 0 != id {
		art.Id = int(id)
	} else if "" != uri {
		art.Uri = uri
	}

	getArt, _ := GetArticle(int(id))
	utils.DelCache("GetArticleByUri.uri." + getArt.Uri)
	utils.DelCache("GetArticle.id." + fmt.Sprintf("%d", art.Id))

	return o.Delete(&art)
}
Ejemplo n.º 2
0
// 更新文章
func UpdateArticle(id int64, uri string, newArt Article) error {
	o := orm.NewOrm()
	o.Using("default")
	var art Article

	if 0 != id {
		art = Article{Id: int(id)}
	} else if "" != uri {
		art = Article{Uri: uri}
	}

	art.Title = newArt.Title
	art.Keywords = newArt.Keywords
	art.Abstract = newArt.Abstract
	art.Content = newArt.Content

	getArt, _ := GetArticle(int(id))
	utils.DelCache("GetArticleByUri.uri." + getArt.Uri)
	utils.DelCache("GetArticle.id." + fmt.Sprintf("%d", art.Id))

	_, err := o.Update(&art, "title", "keywords", "abstract", "content")
	return err
}