github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/routers/root/RReadLink.go (about) 1 package root 2 3 import ( 4 "github.com/insionng/makross" 5 6 "github.com/insionng/yougam/models" 7 ) 8 9 func GetRReadLinkHandler(self *makross.Context) error { 10 11 12 TplNames := "" 13 self.Set("catpage", "RReadLinkHandler") 14 switch linkid := self.Param("linkid").MustInt64(); { 15 //单独模式 16 case linkid > 0: 17 { 18 TplNames = "root/create_link" 19 20 if cat, err := models.GetLink(linkid); cat != nil && err == nil { 21 self.Set("link", *cat) 22 23 if nodes, err := models.GetNodes(0, 0, "id"); nodes != nil && err == nil { 24 self.Set("nodes", nodes) 25 } 26 27 } else { 28 self.Flash.Error(err.Error()) 29 return self.Render(TplNames) 30 31 } 32 } 33 //列表模式 34 case linkid <= 0: 35 { 36 TplNames = "root/link_table" 37 offset := self.Args("offset").MustInt64() 38 limit := self.Args("limit").MustInt64() 39 field := self.FormValue("field") 40 41 if limit == 0 { 42 limit = 1000 //默认限制显示最近1000条,需要显示全部请在提交请求的时候设置limit字段为-1 43 } 44 45 if field == "" { 46 field = "id" 47 } 48 49 if cats, err := models.GetLinks(int(offset), int(limit), field); err == nil && cats != nil { 50 self.Set("links", cats) 51 } 52 } 53 } 54 55 return self.Render(TplNames) 56 }