本文整理匯總了Golang中github.com/urandom/readeef/content.User.HasErr方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.HasErr方法的具體用法?Golang User.HasErr怎麽用?Golang User.HasErr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/urandom/readeef/content.User
的用法示例。
在下文中一共展示了User.HasErr方法的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: 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
}
示例4: 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
}
示例5: 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
}
示例6: 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
}
示例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: 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)
}
示例10: 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
}
示例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: 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
}
示例13: articleCount
func articleCount(u content.User, dbo *db.DB, logger webfw.Logger, opts data.ArticleCountOptions, join, where string, args []interface{}) (count int64) {
if u.HasErr() {
return
}
s := dbo.SQL()
var err error
if articleCountTemplate == nil {
articleCountTemplate, err = template.New("article-count-sql").
Parse(s.User.ArticleCountTemplate)
if err != nil {
u.Err(fmt.Errorf("Error generating article-count template: %v", err))
return
}
}
renderData := articleCountData{}
containsUserFeeds := !opts.UnreadOnly && !opts.FavoriteOnly
if containsUserFeeds {
renderData.Join += s.User.ArticleCountUserFeedsJoin
} else {
if opts.UnreadOnly {
renderData.Join += s.User.ArticleCountUnreadJoin
}
if opts.FavoriteOnly {
renderData.Join += s.User.ArticleCountFavoriteJoin
}
}
if opts.UntaggedOnly {
renderData.Join += s.User.ArticleCountUntaggedJoin
}
if join != "" {
renderData.Join += " " + join
}
args = append([]interface{}{u.Data().Login}, args...)
whereSlice := []string{}
if opts.UnreadOnly {
whereSlice = append(whereSlice, "au.article_id IS NOT NULL AND au.user_login = $1")
}
if opts.FavoriteOnly {
whereSlice = append(whereSlice, "af.article_id IS NOT NULL AND af.user_login = $1")
}
if opts.UntaggedOnly {
whereSlice = append(whereSlice, "uft.feed_id IS NULL")
}
if where != "" {
whereSlice = append(whereSlice, where)
}
if opts.BeforeId > 0 {
whereSlice = append(whereSlice, fmt.Sprintf("a.id < $%d", len(args)+1))
args = append(args, opts.BeforeId)
}
if opts.AfterId > 0 {
whereSlice = append(whereSlice, fmt.Sprintf("a.id > $%d", len(args)+1))
args = append(args, opts.AfterId)
}
if !opts.BeforeDate.IsZero() {
whereSlice = append(whereSlice, fmt.Sprintf("(a.date IS NULL OR a.date < $%d)", len(args)+1))
args = append(args, opts.BeforeDate)
}
if !opts.AfterDate.IsZero() {
whereSlice = append(whereSlice, fmt.Sprintf("a.date > $%d", len(args)+1))
args = append(args, opts.AfterDate)
}
if len(whereSlice) > 0 {
renderData.Where = "WHERE " + strings.Join(whereSlice, " AND ")
}
buf := util.BufferPool.GetBuffer()
defer util.BufferPool.Put(buf)
if err := articleCountTemplate.Execute(buf, renderData); err != nil {
u.Err(fmt.Errorf("Error executing article-count template: %v", err))
return
}
sql := buf.String()
logger.Debugf("Article count SQL:\n%s\nArgs:%v\n", sql, args)
if err := dbo.Get(&count, sql, args...); err != nil {
u.Err(err)
return
}
return
}
示例14: Search
func (e Elastic) Search(
term string, u content.User, feedIds []data.FeedId, limit, offset int,
) (ua []content.UserArticle, err error) {
search := e.client.Search().Index(elasticIndexName)
var query elastic.Query
if t, err := url.QueryUnescape(term); err == nil {
term = t
}
query = elastic.NewCommonTermsQuery("_all", term)
if len(feedIds) > 0 {
idFilter := elastic.NewBoolQuery()
for _, id := range feedIds {
idFilter = idFilter.Should(elastic.NewTermQuery("feed_id", int64(id)))
}
query = elastic.NewBoolQuery().Must(query).Filter(idFilter)
}
search.Query(query)
search.Highlight(elastic.NewHighlight().PreTags("<mark>").PostTags("</mark>").Field("title").Field("description"))
search.From(offset).Size(limit)
switch e.Field() {
case data.SortByDate:
search.Sort("date", e.Order() == data.AscendingOrder)
case data.SortById, data.DefaultSort:
search.Sort("article_id", e.Order() == data.AscendingOrder)
}
var res *elastic.SearchResult
res, err = search.Do()
if err != nil {
return
}
if res.TotalHits() == 0 {
return
}
articleIds := []data.ArticleId{}
highlightMap := map[data.ArticleId]elastic.SearchHitHighlight{}
if res.Hits != nil && res.Hits.Hits != nil {
for _, hit := range res.Hits.Hits {
a := indexArticle{}
if err := json.Unmarshal(*hit.Source, &a); err == nil {
if id, err := strconv.ParseInt(a.ArticleId, 10, 64); err == nil {
articleId := data.ArticleId(id)
articleIds = append(articleIds, articleId)
highlightMap[articleId] = hit.Highlight
}
}
}
}
ua = u.ArticlesById(articleIds)
if u.HasErr() {
return ua, u.Err()
}
for i := range ua {
data := ua[i].Data()
if highlight, ok := highlightMap[data.Id]; ok {
data.Hit.Fragments = map[string][]string{}
if len(highlight["title"]) > 0 {
data.Hit.Fragments["Title"] = highlight["title"]
}
if len(highlight["description"]) > 0 {
data.Hit.Fragments["Description"] = highlight["description"]
}
ua[i].Data(data)
}
}
return
}
示例15: getArticles
func getArticles(u content.User, dbo *db.DB, logger webfw.Logger, sorting content.ArticleSorting, columns, join, where, order string, args []interface{}, paging ...int) (ua []content.UserArticle) {
if u.HasErr() {
return
}
sql := dbo.SQL("get_article_columns")
if columns != "" {
sql += ", " + columns
}
sql += dbo.SQL("get_article_tables")
if join != "" {
sql += " " + join
}
sql += dbo.SQL("get_article_joins")
args = append([]interface{}{u.Data().Login}, args...)
if where != "" {
sql += " AND " + where
}
sortingField := sorting.Field()
sortingOrder := sorting.Order()
fields := []string{}
if order != "" {
fields = append(fields, order)
}
switch sortingField {
case data.SortById:
fields = append(fields, "a.id")
case data.SortByDate:
fields = append(fields, "a.date")
}
if len(fields) > 0 {
sql += " ORDER BY "
sql += strings.Join(fields, ",")
if sortingOrder == data.DescendingOrder {
sql += " DESC"
}
}
if len(paging) > 0 {
limit, offset := pagingLimit(paging)
sql += fmt.Sprintf(" LIMIT $%d OFFSET $%d", len(args)+1, len(args)+2)
args = append(args, limit, offset)
}
var data []data.Article
logger.Debugf("Articles SQL:\n%s\nArgs:%q\n", sql, args)
if err := dbo.Select(&data, sql, args...); err != nil {
u.Err(err)
return
}
ua = make([]content.UserArticle, len(data))
for i := range data {
ua[i] = u.Repo().UserArticle(u)
ua[i].Data(data[i])
}
return
}