This is a creation in Article, where the information may have evolved or changed.
In fact, it can be said that the tutorial has basically ended.
But, do you remember the reminder in the top right corner of our home page? In this chapter, we'll do this thing.
It reminds you that there are updates within the last 1 hours. Well, first of all, there should be a way to query the Blog.go in time.
OK, open the Blog.go Add method:
Func (DAO *dao) findblogsbydate (start time. Time) Int{blogcollection: = Dao.session.DB (DbName). C (blogcollection) Query: = Blogcollection.find (Bson. m{"CDate": Bson. m{"$gte": Start}}) Cnt,err: = Query. Count (); if Err!=nil{revel. WARN. Printf ("Unable to Count blog:error%v", err)}return CNT}
Note that in the Find method of MgO, we have nested two bson. M, the first one is well understood, what is the $gte in the second one? Greater than or equal to (>=) Well, yes, MgO there are other operations, if you need to find a find (say, bloggers in order to find this, but took a time), and finally this method just return a statistic only, yes, we only need this is enough.
In the Controllers/app.go index method, modify:
Func (c App) Index () Revel. Result {DAO, err: = models. Newdao () if err! = Nil {c.response.status = 500return c.rendererror (err)}defer DAO. Close ()//dao: = models. Newdao (c.mongosession) Blogs: = DAO. Findblogs () Now: = time. Now (). ADD ( -1 * time. Hour) recentcnt: =dao. Findblogsbydate (now); return C.render (BLOGS,RECENTCNT)}
The last thing we add a little bit of time to deal with, the current time minus 1 hours, is the result we want. don't forget to add our time package to the import
OK, open the views under the header.html will be inside of:
<li class= "{. Home}" > <a href= "/" >Home</a> <span class= "Navbar-news" title= " 1 updates in the last 1 hours ">1</span> </li>
Modified to:
<li class= "{{. Home}" > <a href= "/" >Home</a> {{if. recentcnt}} {{if GT. recentcnt 0}} <span class= "Navbar-news" title= "the last 1 hours have {{. recentcnt}} Updates" >{{.recentCnt}}</span> {{End}} {{End}} </li>
OK, give it a try.
Finally, here to say, the last RSS, temporarily do not do, I still do not know how to do, to see the GOLANG.USR subscription, just an XML page, this is not what I want, first of all.
Source Address:Https://github.com/joveth/GBlog
AC qq:158325682