本文整理汇总了Golang中github.com/urandom/readeef.FeedManager类的典型用法代码示例。如果您正苦于以下问题:Golang FeedManager类的具体用法?Golang FeedManager怎么用?Golang FeedManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FeedManager类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: addFeeds
func addFeeds(user content.User, fm *readeef.FeedManager, links []string) (resp responseError) {
resp = newResponse()
var err error
errs := make([]addFeedError, 0, len(links))
for _, link := range links {
var u *url.URL
if u, err = url.Parse(link); err != nil {
resp.err = err
errs = append(errs, addFeedError{Link: link, Error: "Error parsing link"})
continue
} else if !u.IsAbs() {
resp.err = errors.New("Feed has no link")
errs = append(errs, addFeedError{Link: link, Error: resp.err.Error()})
continue
} else {
var f content.Feed
if f, err = fm.AddFeedByLink(link); err != nil {
resp.err = err
errs = append(errs, addFeedError{Link: link, Error: "Error adding feed to the database"})
continue
}
uf := user.AddFeed(f)
if uf.HasErr() {
resp.err = f.Err()
errs = append(errs, addFeedError{Link: link, Title: f.Data().Title, Error: "Error adding feed to the database"})
continue
}
tags := strings.SplitN(u.Fragment, ",", -1)
if u.Fragment != "" && len(tags) > 0 {
repo := uf.Repo()
tf := repo.TaggedFeed(user)
tf.Data(uf.Data())
t := make([]content.Tag, len(tags))
for i := range tags {
t[i] = repo.Tag(user)
t[i].Data(data.Tag{Value: data.TagValue(tags[i])})
}
tf.Tags(t)
if tf.UpdateTags(); tf.HasErr() {
resp.err = tf.Err()
errs = append(errs, addFeedError{Link: link, Title: f.Data().Title, Error: "Error adding feed to the database"})
continue
}
}
}
}
resp.val["Errors"] = errs
resp.val["Success"] = len(errs) < len(links)
return
}
开发者ID:urandom,项目名称:readeef,代码行数:57,代码来源:feed.go
示例3: addFeed
func addFeed(user content.User, fm *readeef.FeedManager, links []string) (resp responseError) {
resp = newResponse()
success := false
for _, link := range links {
var u *url.URL
if u, resp.err = url.Parse(link); resp.err != nil {
/* TODO: non-fatal error */
return
} else if !u.IsAbs() {
/* TODO: non-fatal error */
resp.err = errors.New("Feed has no link")
return
} else {
var f content.Feed
if f, resp.err = fm.AddFeedByLink(link); resp.err != nil {
return
}
uf := user.AddFeed(f)
if uf.HasErr() {
resp.err = f.Err()
return
}
tags := strings.SplitN(u.Fragment, ",", -1)
if u.Fragment != "" && len(tags) > 0 {
repo := uf.Repo()
tf := repo.TaggedFeed(user)
tf.Data(uf.Data())
t := make([]content.Tag, len(tags))
for i := range tags {
t[i] = repo.Tag(user)
t[i].Value(data.TagValue(tags[i]))
}
tf.Tags(t)
if tf.UpdateTags(); tf.HasErr() {
resp.err = tf.Err()
return
}
}
success = true
}
}
resp.val["Success"] = success
return
}
开发者ID:RavenB,项目名称:readeef,代码行数:52,代码来源:feed.go
示例4: removeFeed
func removeFeed(user content.User, fm *readeef.FeedManager, id data.FeedId) (resp responseError) {
resp = newResponse()
feed := user.FeedById(id)
if feed.Delete(); feed.HasErr() {
resp.err = feed.Err()
return
}
fm.RemoveFeed(feed)
resp.val["Success"] = true
return
}
开发者ID:urandom,项目名称:readeef,代码行数:14,代码来源:feed.go
示例5: 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
注:本文中的github.com/urandom/readeef.FeedManager类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论