Example #1
0
func SaveBlog(blog Blog) int {
	db := orm.NewOrm()
	blogs := Blog{Index: blog.Index}
	if db.Read(&blogs) == nil {
		blogs.Title = blog.Title
		blogs.Content = blog.Content
		blogs.Created = utils.GetNow()
		blogMap[blog.Index] = blogs
		db.Update(&blogs)
		return 1
	}
	return 0
}
Example #2
0
func SaveNew(blog Blog) {
	db := orm.NewOrm()
	var blogs Blog
	ok, id := true, 0
	for ok {
		id = utils.GetRandId()
		_, ok = blogMap[id]
	}
	blogs.Index = id
	blogs.Title = blog.Title
	blogs.Content = blog.Content
	blogs.Created = utils.GetNow()
	blogMap[blogs.Index] = blogs
	_, err := db.Insert(&blogs)
	if err != nil {
		fmt.Println(err)
	}
}