示例#1
0
func (c Article) Show(id string) revel.Result {
	dao, err := model.NewDao()
	defer dao.Close()
	if err != nil {
		c.Response.Status = 500
		return c.RenderError(err)
	}
	topic := dao.FindTopicById(id)
	if topic == nil {
		return c.Redirect("/")
	}
	if topic.Status == 0 {
		return c.RenderTemplate("Article/result.html")
	}
	ip := strings.Split(c.Request.RemoteAddr, ":")[0]
	revel.INFO.Printf("Ip : %s", ip)
	var obj CacheBean
	key := fmt.Sprintf("%s.%s", ip, id)
	err = cache.Get(key, &obj)
	if err == nil {
		revel.INFO.Printf("Cache : %v", obj)
	} else {
		revel.ERROR.Printf("Cache Errr : %v", err)
		if !obj.HasCache {
			obj.HasCache = true
			go cache.Set(key, obj, 10*time.Minute)
			topic.Read = topic.Read + 1
			dao.UpdateTopic(topic)
		}
	}
	content, ret := utils.GetHTMLContent(id)
	if ret != nil {
		c.Response.Status = 500
		return c.RenderError(ret)
	}
	topic.Body = template.HTML(content)
	replays, repcnt := dao.GetReplays(id)
	return c.Render(topic, replays, repcnt)
}
示例#2
0
func (c Mobile) Show(id string) revel.Result {
	dao, err := model.NewDao()
	defer dao.Close()
	if err != nil {
		c.Response.Status = 500
		return c.RenderError(err)
	}
	topic := dao.FindTopicById(id)
	if topic == nil {
		return c.Redirect("/")
	}
	if topic.Status == 0 {
		return c.RenderTemplate("Article/result.html")
	}
	content, ret := utils.GetHTMLContent(id)
	if ret != nil {
		c.Response.Status = 500
		return c.RenderError(ret)
	}
	revel.INFO.Printf("content: %v", content)
	return c.RenderHtml(content)
}