riviera: hawx.me/code/riviera/feed Index | Files | Directories

package feed

import "hawx.me/code/riviera/feed"

Package feed provides a feed fetcher capable of reading multiple formats into a common structure.


Package Files

database.go feed.go


var ErrUnsupportedFormat = errors.New("Unsupported feed")

ErrUnsupportedFormat is returned when a feed is encountered in a format that is not understood.

func Parse Uses

func Parse(r io.Reader, charset func(charset string, input io.Reader) (io.Reader, error)) (chs []*common.Channel, err error)

Parse reads the content from the provided reader, returning any feed channels found. If the feed is of a format not supported it will return ErrUnsupportedFormat.

type Database Uses

type Database interface {
    Contains(string) bool

A Database allows the Feed to keep track of items it has already seen before.

func NewDatabase Uses

func NewDatabase() Database

NewDatabase returns an empty in-memory database for item keys.

type Feed Uses

type Feed struct {
    // contains filtered or unexported fields

Feed manages polling of a web feed, either in atom, rss, rdf or jsonfeed format.

func New Uses

func New(cachetimeout time.Duration, ih ItemHandler, database Database) *Feed

New creates a new feed that can be polled for updates.

func (*Feed) CanUpdate Uses

func (f *Feed) CanUpdate() bool

CanUpdate returns true or false depending on whether the CacheTimeout value has expired or not. Additionally, it will ensure that we adhere to the RSS spec's SkipDays and SkipHours values. If this function returns true, you can be sure that a fresh feed update will be performed.

func (*Feed) DurationTillUpdate Uses

func (f *Feed) DurationTillUpdate() time.Duration

DurationTillUpdate returns the number of seconds needed to elapse before the feed should update.

func (*Feed) Fetch Uses

func (f *Feed) Fetch(uri string, client *http.Client, charset func(charset string, input io.Reader) (io.Reader, error)) (status int, err error)

Fetch retrieves the feed's latest content if necessary.

The charset parameter overrides the xml decoder's CharsetReader. This allows us to specify a custom character encoding conversion routine when dealing with non-utf8 input. Supply 'nil' to use the default from Go's xml package.

The client parameter allows the use of arbitrary network connections, for example the Google App Engine "URL Fetch" service.

If the feed is unable to update (see CanUpdate) then no request will be made, instead the result will be (status=-1, err=nil).

type ItemHandler Uses

type ItemHandler func(f *Feed, ch *common.Channel, newitems []*common.Item)

ItemHandler is a callback function invoked when a feed has been fetched.


atomPackage atom provides a parser for Atom feeds.
commonPackage common contains structs for a unified feed format.
jsonfeedPackage jsonfeed provides a parser for the jsonfeed format.
rdfPackage rdf provides a parser for RDF Site Summary (RSS) 1.0.
rssPackage rss provides a parser for RSS v2.0 feeds.

Package feed imports 12 packages (graph) and is imported by 10 packages. Updated 2019-04-25. Refresh now. Tools for package owners.