本文整理匯總了Golang中github.com/urandom/readeef/content.User.Err方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.Err方法的具體用法?Golang User.Err怎麽用?Golang User.Err使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/urandom/readeef/content.User
的用法示例。
在下文中一共展示了User.Err方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: articleFavoriteState
func articleFavoriteState(user content.User, id data.ArticleId, favorite bool) (resp responseError) {
resp = newResponse()
article := user.ArticleById(id, data.ArticleQueryOptions{SkipProcessors: true})
if user.HasErr() {
resp.err = user.Err()
return
}
in := article.Data()
previouslyFavorite := in.Favorite
if previouslyFavorite != favorite {
article.Favorite(favorite)
if article.HasErr() {
resp.err = article.Err()
return
}
}
resp.val["Success"] = previouslyFavorite != favorite
resp.val["Favorite"] = favorite
resp.val["Id"] = in.Id
return
}
示例2: getGroups
func getGroups(user content.User) (g []feverGroup, fg []feverFeedsGroup, err error) {
tags := user.Tags()
if user.HasErr() {
err = fmt.Errorf("Error getting user tags: %v", user.Err())
return
}
g = make([]feverGroup, len(tags))
fg = make([]feverFeedsGroup, len(tags))
for i := range tags {
td := tags[i].Data()
g[i] = feverGroup{Id: int64(td.Id), Title: string(td.Value)}
feeds := tags[i].AllFeeds()
if tags[i].HasErr() {
err = fmt.Errorf("Error getting tag feeds: %v", tags[i].Err())
return
}
ids := make([]string, len(feeds))
for j := range feeds {
ids[j] = strconv.FormatInt(int64(feeds[j].Data().Id), 10)
}
fg[i] = feverFeedsGroup{GroupId: int64(td.Id), FeedIds: strings.Join(ids, ",")}
}
return
}
示例3: markArticleAsRead
func markArticleAsRead(user content.User, id data.ArticleId, read bool) (resp responseError) {
resp = newResponse()
article := user.ArticleById(id)
if user.HasErr() {
resp.err = user.Err()
return
}
in := article.Data()
previouslyRead := in.Read
if previouslyRead != read {
article.Read(read)
if article.HasErr() {
resp.err = article.Err()
return
}
}
resp.val["Success"] = previouslyRead != read
resp.val["Read"] = read
resp.val["Id"] = in.Id
return
}
示例4: markArticleAsFavorite
func markArticleAsFavorite(user content.User, id data.ArticleId, favorite bool) (resp responseError) {
resp = newResponse()
article := user.ArticleById(id)
if user.HasErr() {
resp.err = user.Err()
return
}
in := article.Data()
previouslyFavorite := in.Favorite
if previouslyFavorite != favorite {
article.Favorite(favorite)
if article.HasErr() {
resp.err = article.Err()
return
}
}
resp.val["Success"] = previouslyFavorite != favorite
resp.val["Favorite"] = favorite
resp.val["Id"] = in.Id
return
}
示例5: articleReadState
func articleReadState(user content.User, id data.ArticleId, read bool) (resp responseError) {
resp = newResponse()
article := user.ArticleById(id, data.ArticleQueryOptions{SkipProcessors: true})
if user.HasErr() {
resp.err = user.Err()
return
}
in := article.Data()
previouslyRead := in.Read
if previouslyRead != read {
article.Read(read)
if article.HasErr() {
resp.err = article.Err()
return
}
}
resp.val["Success"] = previouslyRead != read
resp.val["Read"] = read
resp.val["Id"] = in.Id
return
}
示例6: formatArticle
func formatArticle(user content.User, id data.ArticleId, webfwConfig webfw.Config, readeefConfig readeef.Config) (resp responseError) {
resp = newResponse()
article := user.ArticleById(id)
if user.HasErr() {
resp.err = user.Err()
return
}
formatting := article.Format(webfwConfig.Renderer.Dir, readeefConfig.ArticleFormatter.ReadabilityKey)
if article.HasErr() {
resp.err = user.Err()
return
}
s := summarize.NewFromString(formatting.Title, readeef.StripTags(formatting.Content))
s.Language = formatting.Language
keyPoints := s.KeyPoints()
for i := range keyPoints {
keyPoints[i] = html.UnescapeString(keyPoints[i])
}
resp.val["KeyPoints"] = keyPoints
resp.val["Content"] = formatting.Content
resp.val["TopImage"] = formatting.TopImage
resp.val["Id"] = id
return
}
示例7: 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
}
示例8: fetchArticle
func fetchArticle(user content.User, id data.ArticleId) (resp responseError) {
resp = newResponse()
article := user.ArticleById(id)
if user.HasErr() {
resp.err = user.Err()
return
}
resp.val["Article"] = article
return
}
示例9: setUserAttribute
func setUserAttribute(user content.User, secret []byte, attr string, data []byte) (resp responseError) {
resp = newResponse()
in := user.Data()
resp.val["Login"] = in.Login
switch attr {
case "FirstName":
resp.err = json.Unmarshal(data, &in.FirstName)
case "LastName":
resp.err = json.Unmarshal(data, &in.LastName)
case "Email":
resp.err = json.Unmarshal(data, &in.Email)
case "ProfileData":
if resp.err = json.Unmarshal(data, &in.ProfileData); resp.err == nil {
in.ProfileJSON = []byte{}
}
case "Active":
in.Active = string(data) == "true"
case "Password":
passwd := struct {
Current string
New string
}{}
if resp.err = json.Unmarshal(data, &passwd); resp.err != nil {
/* TODO: non-fatal error */
return
}
if user.Authenticate(passwd.Current, secret) {
user.Password(passwd.New, secret)
resp.err = user.Err()
} else {
resp.err = errors.New("Error change user password: current password is invalid")
}
default:
resp.err = errors.New("Error getting user attribute: unknown attribute " + attr)
}
if resp.err != nil {
return
}
user.Data(in)
user.Update()
if resp.err = user.Err(); resp.err != nil {
return
}
resp.val["Success"] = true
resp.val["Attribute"] = attr
return
}
示例10: getArticles
func getArticles(u content.User, dbo *db.DB, logger webfw.Logger, opts data.ArticleQueryOptions, sorting content.ArticleSorting, join, where string, args []interface{}) (ua []content.UserArticle) {
if u.HasErr() {
return
}
var err error
if getArticlesTemplate == nil {
getArticlesTemplate, err = template.New("read-state-update-sql").
Parse(dbo.SQL().User.GetArticlesTemplate)
if err != nil {
u.Err(fmt.Errorf("Error generating get-articles-update template: %v", err))
return
}
}
/* Much faster than using 'ORDER BY read'
* TODO: potential overall improvement for fetching pages other than the
* first by using the unread count and moving the offset based on it
*/
if opts.UnreadFirst && opts.Offset == 0 {
originalUnreadOnly := opts.UnreadOnly
opts.UnreadFirst = false
opts.UnreadOnly = true
ua = internalGetArticles(u, dbo, logger, opts, sorting, join, where, args)
if !originalUnreadOnly && (opts.Limit == 0 || opts.Limit > len(ua)) {
if opts.Limit > 0 {
opts.Limit -= len(ua)
}
opts.UnreadOnly = false
opts.ReadOnly = true
readOnly := internalGetArticles(u, dbo, logger, opts, sorting, join, where, args)
ua = append(ua, readOnly...)
}
return
}
return internalGetArticles(u, dbo, logger, opts, sorting, join, where, args)
}
示例11: exportOpml
func exportOpml(user content.User) (resp responseError) {
resp = newResponse()
o := parser.OpmlXml{
Version: "1.1",
Head: parser.OpmlHead{Title: "Feed subscriptions of " + user.String() + " from readeef"},
}
if feeds := user.AllTaggedFeeds(); user.HasErr() {
resp.err = user.Err()
return
} else {
body := parser.OpmlBody{}
for _, f := range feeds {
d := f.Data()
tags := f.Tags()
category := make([]string, len(tags))
for i, t := range tags {
category[i] = string(t.Data().Value)
}
body.Outline = append(body.Outline, parser.OpmlOutline{
Text: d.Title,
Title: d.Title,
XmlUrl: d.Link,
HtmlUrl: d.SiteLink,
Category: strings.Join(category, ","),
Type: "rss",
})
}
o.Body = body
}
var b []byte
if b, resp.err = xml.MarshalIndent(o, "", " "); resp.err != nil {
return
}
resp.val["opml"] = xml.Header + string(b)
return
}
示例12: 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
}
示例13: search
func search(user content.User, searchIndex readeef.SearchIndex, query, highlight, feedId string) (resp responseError) {
resp = newResponse()
if strings.HasPrefix(feedId, "tag:") {
tag := user.Repo().Tag(user)
tag.Value(data.TagValue(feedId[4:]))
tag.Highlight(highlight)
resp.val["Articles"], resp.err = tag.Query(query, searchIndex.Index), tag.Err()
} else {
if id, err := strconv.ParseInt(feedId, 10, 64); err == nil {
f := user.FeedById(data.FeedId(id))
resp.val["Articles"], resp.err = f.Query(query, searchIndex.Index), f.Err()
} else {
user.Highlight(highlight)
resp.val["Articles"], resp.err = user.Query(query, searchIndex.Index), user.Err()
}
}
return
}
示例14: performSearch
func performSearch(user content.User, sp content.SearchProvider, query, feedId string, limit, offset int) (ua []content.UserArticle, err error) {
defer func() {
if rec := recover(); rec != nil {
err = fmt.Errorf("Error during search: %s", rec)
}
}()
if strings.HasPrefix(feedId, "tag:") {
tag := user.Repo().Tag(user)
tag.Data(data.Tag{Value: data.TagValue(feedId[4:])})
ua, err = tag.Query(query, sp, limit, offset), tag.Err()
} else {
if id, err := strconv.ParseInt(feedId, 10, 64); err == nil {
f := user.FeedById(data.FeedId(id))
ua, err = f.Query(query, sp, limit, offset), f.Err()
} else {
ua, err = user.Query(query, sp, limit, offset), user.Err()
}
}
return
}
示例15: markFeedAsRead
func markFeedAsRead(user content.User, id string, timestamp int64) (resp responseError) {
resp = newResponse()
t := time.Unix(timestamp/1000, 0)
switch {
case id == "all":
if user.ReadBefore(t, true); user.HasErr() {
resp.err = user.Err()
return
}
case id == "favorite" || strings.HasPrefix(id, "popular:"):
// Favorites are assumbed to have been read already
case strings.HasPrefix(id, "tag:"):
tag := user.Repo().Tag(user)
tag.Value(data.TagValue(id[4:]))
if tag.ReadBefore(t, true); tag.HasErr() {
resp.err = tag.Err()
return
}
default:
var feedId int64
if feedId, resp.err = strconv.ParseInt(id, 10, 64); resp.err != nil {
/* TODO: non-fatal error */
return
}
feed := user.FeedById(data.FeedId(feedId))
if feed.ReadBefore(t, true); feed.HasErr() {
resp.err = feed.Err()
return
}
}
resp.val["Success"] = true
return
}