本文整理汇总了Golang中github.com/urandom/readeef.FeedManager.AddFeedByLink方法的典型用法代码示例。如果您正苦于以下问题:Golang FeedManager.AddFeedByLink方法的具体用法?Golang FeedManager.AddFeedByLink怎么用?Golang FeedManager.AddFeedByLink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/urandom/readeef.FeedManager
的用法示例。
在下文中一共展示了FeedManager.AddFeedByLink方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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
}