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


Golang User.AllFeeds方法代碼示例

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


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

示例1: discoverFeeds

func discoverFeeds(user content.User, fm *readeef.FeedManager, link string) (resp responseError) {
	resp = newResponse()

	if u, err := url.Parse(link); err != nil {
		resp.err = readeef.ErrNoAbsolute
		resp.errType = errTypeNoAbsolute
		return
	} else if !u.IsAbs() {
		u.Scheme = "http"
		if u.Host == "" {
			parts := strings.SplitN(u.Path, "/", 2)
			u.Host = parts[0]
			if len(parts) > 1 {
				u.Path = "/" + parts[1]
			} else {
				u.Path = ""
			}
		}
		link = u.String()
	}

	feeds, err := fm.DiscoverFeeds(link)
	if err != nil {
		resp.val["Feeds"] = []content.Feed{}
		return
	}

	uf := user.AllFeeds()
	if user.HasErr() {
		resp.err = user.Err()
		return
	}

	userFeedIdMap := make(map[data.FeedId]bool)
	userFeedLinkMap := make(map[string]bool)
	for i := range uf {
		in := uf[i].Data()
		userFeedIdMap[in.Id] = true
		userFeedLinkMap[in.Link] = true

		u, err := url.Parse(in.Link)
		if err == nil && strings.HasPrefix(u.Host, "www.") {
			u.Host = u.Host[4:]
			userFeedLinkMap[u.String()] = true
		}
	}

	respFeeds := []content.Feed{}
	for i := range feeds {
		in := feeds[i].Data()
		if !userFeedIdMap[in.Id] && !userFeedLinkMap[in.Link] {
			respFeeds = append(respFeeds, feeds[i])
		}
	}

	resp.val["Feeds"] = respFeeds
	return
}
開發者ID:urandom,項目名稱:readeef,代碼行數:58,代碼來源:feed.go

示例2: parseOpml

func parseOpml(user content.User, fm *readeef.FeedManager, opmlData []byte) (resp responseError) {
	resp = newResponse()

	var opml parser.Opml
	if opml, resp.err = parser.ParseOpml(opmlData); resp.err != nil {
		return
	}

	uf := user.AllFeeds()
	if user.HasErr() {
		resp.err = user.Err()
		return
	}

	userFeedMap := make(map[data.FeedId]bool)
	for i := range uf {
		userFeedMap[uf[i].Data().Id] = true
	}

	var feeds []content.Feed
	for _, opmlFeed := range opml.Feeds {
		discovered, err := fm.DiscoverFeeds(opmlFeed.Url)
		if err != nil {
			continue
		}

		for _, f := range discovered {
			in := f.Data()
			if !userFeedMap[in.Id] {
				if len(opmlFeed.Tags) > 0 {
					in.Link += "#" + strings.Join(opmlFeed.Tags, ",")
				}

				f.Data(in)

				feeds = append(feeds, f)
			}
		}
	}

	resp.val["Feeds"] = feeds
	return
}
開發者ID:urandom,項目名稱:readeef,代碼行數:43,代碼來源:feed.go

示例3: Handler


//.........這裏部分代碼省略.........
					case TTRSS_ALL_ID, 0:
						ar = user
					default:
						if req.FeedId > 0 {
							feed := user.FeedById(req.FeedId)
							if feed.HasErr() {
								err = feed.Err()
								break
							}

							ar = feed
						}

					}

				}

				if ar == nil {
					con = ttRssGenericContent{Unread: "0"}
				} else if con == nil {
					con = ttRssGenericContent{Unread: strconv.FormatInt(ar.Count(o), 10)}
				}
			case "getCounters":
				if req.OutputMode == "" {
					req.OutputMode = "flc"
				}
				cContent := ttRssCountersContent{}

				o := data.ArticleCountOptions{UnreadOnly: true}
				unreadCount := user.Count(o)
				cContent = append(cContent,
					ttRssCounter{Id: "global-unread", Counter: unreadCount})

				feeds := user.AllFeeds()
				cContent = append(cContent,
					ttRssCounter{Id: "subscribed-feeds", Counter: int64(len(feeds))})

				cContent = append(cContent, ttRssCounter{Id: TTRSS_ARCHIVED_ID})

				cContent = append(cContent,
					ttRssCounter{Id: TTRSS_FAVORITE_ID,
						Counter:    user.Count(data.ArticleCountOptions{UnreadOnly: true, FavoriteOnly: true}),
						AuxCounter: user.Count(data.ArticleCountOptions{FavoriteOnly: true})})

				cContent = append(cContent, ttRssCounter{Id: TTRSS_PUBLISHED_ID})

				freshTime := time.Now().Add(TTRSS_FRESH_DURATION)
				cContent = append(cContent,
					ttRssCounter{Id: TTRSS_FRESH_ID,
						Counter:    user.Count(data.ArticleCountOptions{UnreadOnly: true, AfterDate: freshTime}),
						AuxCounter: 0})

				cContent = append(cContent,
					ttRssCounter{Id: TTRSS_ALL_ID,
						Counter:    user.Count(),
						AuxCounter: 0})

				for _, f := range feeds {
					cContent = append(cContent,
						ttRssCounter{Id: int64(f.Data().Id), Counter: f.Count(o)},
					)

				}

				cContent = append(cContent, ttRssCounter{Id: TTRSS_CAT_LABELS, Counter: 0, Kind: "cat"})
開發者ID:urandom,項目名稱:readeef,代碼行數:66,代碼來源:tt_rss.go

示例4: 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.AllFeeds方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。