當前位置: 首頁>>代碼示例>>Golang>>正文


Golang User.SortingByDate方法代碼示例

本文整理匯總了Golang中github.com/urandom/readeef/content.User.SortingByDate方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.SortingByDate方法的具體用法?Golang User.SortingByDate怎麽用?Golang User.SortingByDate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/urandom/readeef/content.User的用法示例。


在下文中一共展示了User.SortingByDate方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getFeedArticles

func getFeedArticles(user content.User, id string, limit int, offset int, newerFirst bool, unreadOnly bool) (resp responseError) {
	resp = newResponse()

	if limit > 50 {
		limit = 50
	}

	user.SortingByDate()
	if newerFirst {
		user.Order(data.DescendingOrder)
	} else {
		user.Order(data.AscendingOrder)
	}
	if id == "favorite" {
		resp.val["Articles"], resp.err = user.FavoriteArticles(limit, offset), user.Err()
	} else if id == "popular:all" {
		resp.val["Articles"], resp.err = user.ScoredArticles(time.Now().AddDate(0, 0, -5), time.Now(), limit, offset), user.Err()
	} else if id == "all" {
		if unreadOnly {
			resp.val["Articles"], resp.err = user.UnreadArticles(limit, offset), user.Err()
		} else {
			resp.val["Articles"], resp.err = user.Articles(limit, offset), user.Err()
		}
	} else if strings.HasPrefix(id, "popular:") {
		if strings.HasPrefix(id, "popular:tag:") {
			tag := user.Repo().Tag(user)
			tag.Value(data.TagValue(id[12:]))

			tag.SortingByDate()
			if newerFirst {
				tag.Order(data.DescendingOrder)
			} else {
				tag.Order(data.AscendingOrder)
			}
			resp.val["Articles"], resp.err = tag.ScoredArticles(time.Now().AddDate(0, 0, -5), time.Now(), limit, offset), tag.Err()
		} else {
			var f content.UserFeed

			var feedId int64
			feedId, resp.err = strconv.ParseInt(id[8:], 10, 64)

			if resp.err != nil {
				resp.err = errors.New("Unknown feed id " + id)
				return
			}

			if f = user.FeedById(data.FeedId(feedId)); f.HasErr() {
				/* TODO: non-fatal error */
				resp.err = f.Err()
				return
			}

			f.SortingByDate()
			if newerFirst {
				f.Order(data.DescendingOrder)
			} else {
				f.Order(data.AscendingOrder)
			}

			resp.val["Articles"], resp.err = f.ScoredArticles(time.Now().AddDate(0, 0, -5), time.Now(), limit, offset), f.Err()
		}
	} else if strings.HasPrefix(id, "tag:") {
		tag := user.Repo().Tag(user)
		tag.Value(data.TagValue(id[4:]))

		tag.SortingByDate()
		if newerFirst {
			tag.Order(data.DescendingOrder)
		} else {
			tag.Order(data.AscendingOrder)
		}

		if unreadOnly {
			resp.val["Articles"], resp.err = tag.UnreadArticles(limit, offset), tag.Err()
		} else {
			resp.val["Articles"], resp.err = tag.Articles(limit, offset), tag.Err()
		}
	} else {
		var f content.UserFeed

		var feedId int64
		feedId, resp.err = strconv.ParseInt(id, 10, 64)

		if resp.err != nil {
			resp.err = errors.New("Unknown feed id " + id)
			return
		}

		if f = user.FeedById(data.FeedId(feedId)); f.HasErr() {
			/* TODO: non-fatal error */
			resp.err = f.Err()
			return
		}

		if newerFirst {
			f.Order(data.DescendingOrder)
		} else {
			f.Order(data.AscendingOrder)
		}

//.........這裏部分代碼省略.........
開發者ID:RavenB,項目名稱:readeef,代碼行數:101,代碼來源:feed.go

示例2: Handler


//.........這裏部分代碼省略.........

			if _, ok := r.Form["links"]; ok {
				reqType = "links"
				logger.Infoln("Fetching fever links")
				offset, _ := strconv.ParseInt(r.FormValue("offset"), 10, 64)

				rng, e := strconv.ParseInt(r.FormValue("range"), 10, 64)
				if e != nil {
					rng = 7
				}

				page := int64(1)
				page, err = strconv.ParseInt(r.FormValue("page"), 10, 64)
				if e != nil {
					break
				}

				if page > 3 {
					resp["links"] = []feverLink{}
					break
				}

				var articles []content.UserArticle
				var from, to time.Time

				if offset == 0 {
					from = time.Now().AddDate(0, 0, int(-1*rng))
					to = time.Now()
				} else {
					from = time.Now().AddDate(0, 0, int(-1*rng-offset))
					to = time.Now().AddDate(0, 0, int(-1*offset))
				}

				user.SortingByDate()
				user.Order(data.DescendingOrder)

				articles, err = user.Articles(data.ArticleQueryOptions{
					BeforeDate:    to,
					AfterDate:     from,
					Limit:         50,
					Offset:        50 * int(page-1),
					IncludeScores: true,
				}), user.Err()
				if err != nil {
					break
				}

				links := make([]feverLink, len(articles))
				for i := range articles {
					in := articles[i].Data()

					link := feverLink{
						Id: in.Id, FeedId: in.FeedId, ItemId: in.Id, IsItem: 1,
						IsLocal: 1, Title: in.Title, Url: in.Link, ItemIds: fmt.Sprintf("%d", in.Id),
					}

					if in.Score == 0 {
						link.Temperature = 0
					} else {
						link.Temperature = math.Log10(float64(in.Score)) / math.Log10(1.1)
					}

					if in.Favorite {
						link.IsSaved = 1
					}
開發者ID:urandom,項目名稱:readeef,代碼行數:66,代碼來源:fever.go


注:本文中的github.com/urandom/readeef/content.User.SortingByDate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。