本文整理汇总了Golang中github.com/royburns/roysblog/models.Post.Update方法的典型用法代码示例。如果您正苦于以下问题:Golang Post.Update方法的具体用法?Golang Post.Update怎么用?Golang Post.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/royburns/roysblog/models.Post
的用法示例。
在下文中一共展示了Post.Update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Show
//文章显示
func (this *MainController) Show() {
var (
post *models.Post = new(models.Post)
err error
)
urlname := this.Ctx.Input.Param(":urlname")
if urlname != "" {
post.Urlname = urlname
err = post.Read("urlname")
} else {
id, _ := strconv.Atoi(this.Ctx.Input.Param(":id"))
post.Id = int64(id)
err = post.Read()
}
if err != nil || post.Status != 0 {
this.Redirect("/404.html", 302)
}
post.Views++
post.Update("Views")
models.Cache.Delete("hotblog")
post.Content = strings.Replace(post.Content, "_ueditor_page_break_tag_", "", -1)
pre, next := post.GetPreAndNext()
this.Data["post"] = post
this.Data["pre"] = pre
this.Data["next"] = next
this.Data["smalltitle"] = "文章内容"
if urlname == "about.html" {
this.Data["smalltitle"] = "关于我"
}
this.setHeadMetas(post.Title, strings.Trim(post.Tags, ","), post.Title)
this.display("article")
}
示例2: Save
//保存
func (this *ArticleController) Save() {
var (
id int64 = 0
title string = strings.TrimSpace(this.GetString("title"))
content string = this.GetString("content")
tags string = strings.TrimSpace(this.GetString("tags"))
urlname string = strings.TrimSpace(this.GetString("urlname"))
color string = strings.TrimSpace(this.GetString("color"))
cover string = strings.TrimSpace(this.GetString("cover"))
timestr string = strings.TrimSpace(this.GetString("posttime"))
status int64 = 0
istop int8 = 0
urltype int8 = 0
post models.Post
)
if title == "" {
this.showmsg("标题不能为空!")
}
id, _ = this.GetInt64("id")
status, _ = this.GetInt64("status")
if this.GetString("istop") == "1" {
istop = 1
}
if this.GetString("urltype") == "1" {
urltype = 1
}
if status != 1 && status != 2 {
status = 0
}
if cover == "" {
cover = "/static/upload/defaultcover.png"
}
addtags := make([]string, 0)
//标签过滤
if tags != "" {
tagarr := strings.Split(tags, ",")
for _, v := range tagarr {
if tag := strings.TrimSpace(v); tag != "" {
exists := false
for _, vv := range addtags {
if vv == tag {
exists = true
break
}
}
if !exists {
addtags = append(addtags, tag)
}
}
}
}
if id < 1 {
post.Userid = this.userid
post.Author = this.username
post.Posttime = this.getTime()
post.Updated = this.getTime()
post.Insert()
models.Cache.Delete("latestblog")
} else {
post.Id = id
if post.Read() != nil {
goto RD
}
if post.Tags != "" {
var tagobj models.Tag
var tagpostobj models.TagPost
oldtags := strings.Split(strings.Trim(post.Tags, ","), ",")
//标签统计-1
tagobj.Query().Filter("name__in", oldtags).Update(orm.Params{"count": orm.ColValue(orm.Col_Minus, 1)})
//删掉tag_post表的记录
tagpostobj.Query().Filter("postid", post.Id).Delete()
}
}
if len(addtags) > 0 {
for _, v := range addtags {
tag := models.Tag{Name: v}
if tag.Read("Name") == orm.ErrNoRows {
tag.Count = 1
tag.Insert()
} else {
tag.Count += 1
tag.Update("Count")
}
tp := models.TagPost{Tagid: tag.Id, Postid: post.Id, Poststatus: int8(status), Posttime: this.getTime()}
tp.Insert()
}
post.Tags = "," + strings.Join(addtags, ",") + ","
}
if posttime, err := time.Parse("2006-01-02 15:04:05", timestr); err == nil {
post.Posttime = posttime
} else {
post.Posttime, _ = time.Parse("2006-01-02 15:04:05", post.Posttime.Format("2006-01-02 15:04:05"))
}
post.Status = int8(status)
//.........这里部分代码省略.........