Example #1
0
func GetFileList(page, size int) ([]*File, *utils.Pager) {
	pager := utils.NewPager(page, size, len(files))
	f := make([]*File, 0)
	if page > pager.Pages || len(files) < 1 {
		return f, pager
	}
	for i := pager.Begin; i <= pager.End; i++ {
		f = files[pager.Begin-1 : pager.End]
	}
	return f, pager
}
Example #2
0
// GetCommentList returns a comments list and pager.
// This list scans all comments no matter its status.
func GetCommentList(page, size int) ([]*Comment, *utils.Pager) {
	index := commentsIndex
	pager := utils.NewPager(page, size, len(index))
	comments := make([]*Comment, 0)
	if page > pager.Pages {
		return comments, pager
	}
	for i := pager.Begin; i <= pager.End; i++ {
		comments = append(comments, GetCommentById(index[i-1]))
	}
	return comments, pager
}
Example #3
0
// get pages list.
func GetPageList(page, size int) ([]*Content, *utils.Pager) {
	index := contentsIndex["page"]
	pager := utils.NewPager(page, size, len(index))
	pages := make([]*Content, 0)
	if page > pager.Pages {
		return pages, pager
	}
	for i := pager.Begin; i <= pager.End; i++ {
		pages = append(pages, GetContentById(index[i-1]))
	}
	return pages, pager
}
Example #4
0
// GetTaggedArticleList returns tagged articles list.
// These articles contains same one tag.
func GetTaggedArticleList(tag string, page, size int) ([]*Content, *utils.Pager) {
	index := contentsIndex["t-"+tag]
	pager := utils.NewPager(page, size, len(index))
	articles := make([]*Content, 0)
	if len(index) < 1 {
		return articles, pager
	}
	if page > pager.Pages {
		return articles, pager
	}
	for i := pager.Begin; i <= pager.End; i++ {
		articles = append(articles, GetContentById(index[i-1]))
	}
	return articles, pager
}
Example #5
0
// GetPopularArticleList returns popular articles list.
// Popular articles are ordered by comment number.
func GetPopularArticleList(size int) []*Content {
	index := contentsIndex["article-pop"]
	pager := utils.NewPager(1, size, len(index))
	articles := make([]*Content, 0)
	if len(index) < 1 {
		return articles
	}
	if 1 > pager.Pages {
		return articles
	}
	for i := pager.Begin; i <= pager.End; i++ {
		articles = append(articles, GetContentById(index[i-1]))
	}
	return articles
}