本文整理匯總了Golang中github.com/urandom/readeef.FeedManager.DiscoverFeeds方法的典型用法代碼示例。如果您正苦於以下問題:Golang FeedManager.DiscoverFeeds方法的具體用法?Golang FeedManager.DiscoverFeeds怎麽用?Golang FeedManager.DiscoverFeeds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/urandom/readeef.FeedManager
的用法示例。
在下文中一共展示了FeedManager.DiscoverFeeds方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
示例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
}