本文整理汇总了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
}