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


Golang User.Ids方法代碼示例

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


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

示例1: Handler

func (con Fever) Handler(c context.Context) http.Handler {
	repo := readeef.GetRepo(c)
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		logger := webfw.GetLogger(c)

		var err error
		var user content.User

		err = r.ParseForm()

		if err == nil {
			user = getReadeefUser(repo, r.FormValue("api_key"), webfw.GetLogger(c))
		}

		resp := map[string]interface{}{"api_version": FEVER_API_VERSION}
		var reqType string

		switch {
		default:
			if user == nil {
				resp["auth"] = 0
				break
			}

			now := time.Now().Unix()

			resp["auth"] = 1
			resp["last_refreshed_on_time"] = now

			if _, ok := r.Form["groups"]; ok {
				reqType = "groups"
				logger.Infoln("Fetching fever groups")

				resp["groups"], resp["feeds_groups"], err = getGroups(user)
			}

			if _, ok := r.Form["feeds"]; ok {
				reqType = "feeds"
				logger.Infoln("Fetching fever feeds")

				var feverFeeds []feverFeed

				feeds := user.AllFeeds()
				err = user.Err()

				if err != nil {
					break
				}

				for i := range feeds {
					in := feeds[i].Data()
					feed := feverFeed{
						Id: in.Id, Title: in.Title, Url: in.Link, SiteUrl: in.SiteLink, UpdateTime: now,
					}

					feverFeeds = append(feverFeeds, feed)
				}

				resp["feeds"] = feverFeeds
				_, resp["feeds_groups"], err = getGroups(user)
			}

			if _, ok := r.Form["unread_item_ids"]; ok {
				reqType = "unread item ids"
				logger.Infoln("Fetching unread fever item ids")

				ids := user.Ids(data.ArticleIdQueryOptions{UnreadOnly: true})
				err = user.Err()
				if err != nil {
					break
				}

				buf := util.BufferPool.GetBuffer()
				defer util.BufferPool.Put(buf)

				for i := range ids {
					if i != 0 {
						buf.WriteString(",")
					}

					buf.WriteString(strconv.FormatInt(int64(ids[i]), 10))
				}

				resp["unread_item_ids"] = buf.String()
			}

			if _, ok := r.Form["saved_item_ids"]; ok {
				reqType = "saved item ids"
				logger.Infoln("Fetching saved fever item ids")

				ids := user.Ids(data.ArticleIdQueryOptions{FavoriteOnly: true})
				err = user.Err()
				if err != nil {
					break
				}

				buf := util.BufferPool.GetBuffer()
				defer util.BufferPool.Put(buf)

				for i := range ids {
//.........這裏部分代碼省略.........
開發者ID:urandom,項目名稱:readeef,代碼行數:101,代碼來源:fever.go


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