当前位置: 首页>>代码示例>>Golang>>正文


Golang content.Feed类代码示例

本文整理汇总了Golang中github.com/urandom/readeef/content.Feed的典型用法代码示例。如果您正苦于以下问题:Golang Feed类的具体用法?Golang Feed怎么用?Golang Feed使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Feed类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: FeedUpdated

func (t Thumbnailer) FeedUpdated(feed content.Feed) error {
	t.logger.Debugln("Generating thumbnailer processors")

	processors := t.generateProcessors(feed.NewArticles())
	numProcessors := 20
	done := make(chan struct{})
	errc := make(chan error)

	defer close(done)

	var wg sync.WaitGroup

	wg.Add(numProcessors)
	for i := 0; i < numProcessors; i++ {
		go func() {
			err := t.process(done, processors)
			if err != nil {
				errc <- err
			}
			wg.Done()
		}()
	}

	go func() {
		wg.Wait()
		close(errc)
	}()

	for err := range errc {
		return err
	}

	return nil
}
开发者ID:urandom,项目名称:readeef,代码行数:34,代码来源:thumbnailer.go

示例2: Unsubscribe

func (h Hubbub) Unsubscribe(f content.Feed) error {
	if u, err := url.Parse(h.config.Hubbub.CallbackURL); err != nil {
		return ErrNotConfigured
	} else {
		if !u.IsAbs() {
			return ErrNotConfigured
		}
	}

	fdata := f.Data()
	if u, err := url.Parse(fdata.HubLink); err != nil {
		return ErrNoFeedHubLink
	} else {
		if !u.IsAbs() {
			return ErrNoFeedHubLink
		}
	}

	s := f.Subscription()
	if s.HasErr() {
		return s.Err()
	}

	if s.Data().FeedId != fdata.Id {
		h.logger.Infoln("Not subscribed to " + fdata.HubLink)
		return ErrNotSubscribed
	}

	go func() {
		h.subscription(s, f, false)
	}()
	return nil
}
开发者ID:urandom,项目名称:readeef,代码行数:33,代码来源:hubbub.go

示例3: startUpdatingFeed

func (fm *FeedManager) startUpdatingFeed(f content.Feed) {
	if f == nil {
		fm.logger.Infoln("No feed provided")
		return
	}

	data := f.Data()

	if data.Id == 0 || fm.activeFeeds[data.Id] {
		fm.logger.Infoln("Feed " + data.Link + " already active")
		return
	}

	d := 30 * time.Minute
	if fm.config.FeedManager.Converted.UpdateInterval != 0 {
		if data.TTL != 0 && data.TTL > fm.config.FeedManager.Converted.UpdateInterval {
			d = data.TTL
		} else {
			d = fm.config.FeedManager.Converted.UpdateInterval
		}
	}

	fm.activeFeeds[data.Id] = true

	go func() {
		fm.requestFeedContent(f)

		ticker := time.After(d)

		fm.logger.Infof("Starting feed scheduler for %s and duration %d\n", f, d)
	TICKER:
		for {
			select {
			case now := <-ticker:
				if !fm.activeFeeds[data.Id] {
					fm.logger.Infof("Feed '%s' no longer active\n", data.Link)
					break TICKER
				}

				if !data.SkipHours[now.Hour()] && !data.SkipDays[now.Weekday().String()] {
					fm.requestFeedContent(f)
				}

				ticker = time.After(d)
				fm.logger.Infof("New feed ticker for '%s' after %d\n", data.Link, d)
			case <-fm.done:
				fm.stopUpdatingFeed(f)
				return
			}
		}
	}()

	go fm.scoreFeedContent(f)
}
开发者ID:urandom,项目名称:readeef,代码行数:54,代码来源:feed_manager.go

示例4: AddFeed

func (fm *FeedManager) AddFeed(f content.Feed) {
	if f.Data().HubLink != "" && fm.hubbub != nil {
		err := fm.hubbub.Subscribe(f)

		if err == nil || err == ErrSubscribed {
			return
		}
	}

	fm.addFeed <- f
}
开发者ID:urandom,项目名称:readeef,代码行数:11,代码来源:feed_manager.go

示例5: processFeedUpdateMonitors

func (fm FeedManager) processFeedUpdateMonitors(f content.Feed) {
	if len(f.NewArticles()) > 0 {
		for _, m := range fm.feedMonitors {
			if err := m.FeedUpdated(f); err != nil {
				fm.logger.Printf("Error invoking monitor '%s' on updated feed '%s': %v\n",
					reflect.TypeOf(m), f, err)
			}
		}
	} else {
		fm.logger.Infoln("No new articles for " + f.String())
	}
}
开发者ID:urandom,项目名称:readeef,代码行数:12,代码来源:feed_manager.go

示例6: 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

示例7: FeedDeleted

func (i Index) FeedDeleted(feed content.Feed) error {
	i.logger.Infof("Deleting article search index for feed '%s'\n", feed)

	articles := feed.AllArticles()

	if feed.HasErr() {
		return fmt.Errorf("Error deleting all articles of %s from the search index: %v\n", feed, feed.Err())
	} else {
		i.logger.Infof("Deleting article search index for feed '%s'\n", feed)

		return i.provider.BatchIndex(articles, data.BatchDelete)
	}

}
开发者ID:urandom,项目名称:readeef,代码行数:14,代码来源:index.go

示例8: requestFeedContent

func (fm *FeedManager) requestFeedContent(f content.Feed) {
	if f == nil {
		fm.logger.Infoln("No feed provided")
		return
	}

	data := f.Data()

	fm.logger.Infoln("Requesting feed content for " + f.String())

	resp, err := fm.client.Get(data.Link)

	if err != nil {
		data.UpdateError = err.Error()
	} else if resp.StatusCode != http.StatusOK {
		defer func() {
			// Drain the body so that the connection can be reused
			io.Copy(ioutil.Discard, resp.Body)
			resp.Body.Close()
		}()
		data.UpdateError = httpStatusPrefix + strconv.Itoa(resp.StatusCode)
	} else {
		defer resp.Body.Close()
		data.UpdateError = ""

		buf := util.BufferPool.GetBuffer()
		defer util.BufferPool.Put(buf)

		if _, err := buf.ReadFrom(resp.Body); err == nil {
			hash := md5.Sum(buf.Bytes())
			if b, ok := fm.lastUpdateHash[data.Id]; ok && bytes.Equal(b[:], hash[:]) {
				fm.logger.Infof("Content of feed %s is the same as the previous update\n", f)
				return
			}
			fm.lastUpdateHash[data.Id] = hash

			if pf, err := parser.ParseFeed(buf.Bytes(), parser.ParseRss2, parser.ParseAtom, parser.ParseRss1); err == nil {
				f.Refresh(fm.processParserFeed(pf))
			} else {
				data.UpdateError = err.Error()
			}
		} else {
			data.UpdateError = err.Error()
		}

	}

	if data.UpdateError != "" {
		fm.logger.Printf("Error updating feed '%s': %s\n", f, data.UpdateError)
	}

	f.Data(data)

	select {
	case <-fm.done:
		return
	default:
		fm.updateFeed(f)
	}
}
开发者ID:urandom,项目名称:readeef,代码行数:60,代码来源:feed_manager.go

示例9: TestImplements

func TestImplements(t *testing.T) {
	var article content.Article

	r := NewRepo(nil, nil)

	article = r.Article()
	article.Data()

	var userArticle content.UserArticle

	userArticle = r.UserArticle(nil)
	userArticle.Data()

	var scoredArticle content.ScoredArticle

	scoredArticle = r.ScoredArticle()
	scoredArticle.Data()

	var feed content.Feed

	feed = r.Feed()
	feed.Data()

	var userFeed content.UserFeed

	userFeed = r.UserFeed(nil)
	userFeed.Data()

	var taggedFeed content.TaggedFeed

	taggedFeed = r.TaggedFeed(nil)
	taggedFeed.Data()

	r.HasErr()

	var subscription content.Subscription

	subscription = r.Subscription()
	subscription.Data()

	var tag content.Tag

	tag = r.Tag(nil)
	tag.Value()

	var user content.User

	user = r.User()
	user.Data()
}
开发者ID:RavenB,项目名称:readeef,代码行数:50,代码来源:implementation_test.go

示例10: Subscribe

func (h *Hubbub) Subscribe(f content.Feed) error {
	if u, err := url.Parse(h.config.Hubbub.CallbackURL); err != nil {
		return ErrNotConfigured
	} else {
		if !u.IsAbs() {
			return ErrNotConfigured
		}
	}

	fdata := f.Data()
	if u, err := url.Parse(fdata.HubLink); err != nil {
		return ErrNoFeedHubLink
	} else {
		if !u.IsAbs() {
			return ErrNoFeedHubLink
		}
	}

	s := f.Subscription()
	if s.HasErr() {
		return s.Err()
	}

	data := s.Data()
	if data.FeedId == fdata.Id {
		h.logger.Infoln("Already subscribed to " + fdata.HubLink)
		return ErrSubscribed
	}

	data.Link = fdata.HubLink
	data.FeedId = fdata.Id
	data.SubscriptionFailure = true

	s.Data(data)
	s.Update()

	if s.HasErr() {
		return s.Err()
	}

	go func() {
		h.subscribe(s, f, true)
	}()

	return nil
}
开发者ID:RavenB,项目名称:readeef,代码行数:46,代码来源:hubbub.go

示例11: UpdateFeed

func (si SearchIndex) UpdateFeed(feed content.Feed) {
	si.logger.Infof("Updating article search index for feed '%s'\n", feed)

	newArticleLinks := map[string]bool{}
	for _, a := range feed.NewArticles() {
		newArticleLinks[a.Data().Link] = true
	}

	var articles []content.Article
	for _, a := range feed.ParsedArticles() {
		if newArticleLinks[a.Data().Link] {
			articles = append(articles, a)
		}
	}

	si.batchIndex(articles)
}
开发者ID:RavenB,项目名称:readeef,代码行数:17,代码来源:search_index.go

示例12: AddFeed

func (u *User) AddFeed(f content.Feed) (uf content.UserFeed) {
	uf = u.Repo().UserFeed(u)
	if u.HasErr() {
		uf.Err(u.Err())
		return
	}

	if err := u.Validate(); err != nil {
		u.Err(err)
		return
	}

	d := f.Data()
	if f.HasErr() {
		uf.Data(d)
		uf.Err(f.Err())
		return
	}

	if err := f.Validate(); err != nil {
		uf.Err(err)
		return
	}

	login := u.Data().Login
	u.logger.Infof("Getting user feed for user %s and feed %d\n", login, d.Id)

	tx, err := u.db.Beginx()
	if err != nil {
		uf.Err(err)
		return
	}
	defer tx.Rollback()

	stmt, err := tx.Preparex(u.db.SQL().User.CreateFeed)
	if err != nil {
		uf.Err(err)
		return
	}
	defer stmt.Close()

	_, err = stmt.Exec(u.Data().Login, d.Id)
	if err != nil {
		uf.Err(err)
		return
	}

	if err := tx.Commit(); err != nil {
		uf.Err(err)
	}

	uf.Data(d)

	return
}
开发者ID:urandom,项目名称:readeef,代码行数:55,代码来源:user.go

示例13: 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

示例14: updateFeed

func (fm FeedManager) updateFeed(f content.Feed) {
	f.Update()

	if f.HasErr() {
		fm.logger.Printf("Error updating feed '%s' database record: %v\n", f, f.Err())
	} else {
		fm.processFeedUpdateMonitors(f)
	}
}
开发者ID:urandom,项目名称:readeef,代码行数:9,代码来源:feed_manager.go

示例15: FeedUpdated

func (i Unread) FeedUpdated(feed content.Feed) error {
	i.logger.Infof("Adding 'unread' states for all new articles of %s' for all users\n", feed)

	feed.SetNewArticlesUnread()

	if feed.HasErr() {
		return feed.Err()
	} else {
		return nil
	}
}
开发者ID:urandom,项目名称:readeef,代码行数:11,代码来源:unread.go


注:本文中的github.com/urandom/readeef/content.Feed类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。