feed

package
v0.0.0-...-44d4e1f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2022 License: MIT, CC0-1.0 Imports: 14 Imported by: 1

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

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

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

Functions

func Parse

func Parse(r io.Reader, rootURL *url.URL, 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.

Types

type Database

type Database interface {
	Contains(string) bool
}

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

func NewDatabase

func NewDatabase() Database

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

type Feed

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

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

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

func (*Feed) CanUpdate

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

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

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

func (*Feed) Fetch

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

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

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

Directories

Path Synopsis
Package atom provides a parser for Atom feeds.
Package atom provides a parser for Atom feeds.
Package common contains structs for a unified feed format.
Package common contains structs for a unified feed format.
Package hfeed provides a parser for h-feeds.
Package hfeed provides a parser for h-feeds.
Package jsonfeed provides a parser for the jsonfeed format.
Package jsonfeed provides a parser for the jsonfeed format.
Package rdf provides a parser for RDF Site Summary (RSS) 1.0.
Package rdf provides a parser for RDF Site Summary (RSS) 1.0.
Package rss provides a parser for RSS v2.0 feeds.
Package rss provides a parser for RSS v2.0 feeds.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL