type DefaultAtomTranslator struct{}
DefaultAtomTranslator converts an atom.Feed struct into the generic Feed struct.
This default implementation defines a set of mapping rules between atom.Feed -> Feed for each of the fields in Feed.
func (t *DefaultAtomTranslator) Translate(feed interface{}) (*Feed, error)
Translate converts an Atom feed into the universal feed type.
type DefaultRSSTranslator struct{}
DefaultRSSTranslator converts an rss.Feed struct into the generic Feed struct.
This default implementation defines a set of mapping rules between rss.Feed -> Feed for each of the fields in Feed.
func (t *DefaultRSSTranslator) Translate(feed interface{}) (*Feed, error)
Translate converts an RSS feed into the universal feed type.
type Enclosure struct { URL string `json:"url,omitempty"` Length string `json:"length,omitempty"` Type string `json:"type,omitempty"` }
Enclosure is a file associated with a given Item.
type Feed struct { Title string `json:"title,omitempty"` Description string `json:"description,omitempty"` Link string `json:"link,omitempty"` FeedLink string `json:"feedLink,omitempty"` Updated string `json:"updated,omitempty"` UpdatedParsed *time.Time `json:"updatedParsed,omitempty"` Published string `json:"published,omitempty"` PublishedParsed *time.Time `json:"publishedParsed,omitempty"` Author *Person `json:"author,omitempty"` Language string `json:"language,omitempty"` Image *Image `json:"image,omitempty"` Copyright string `json:"copyright,omitempty"` Generator string `json:"generator,omitempty"` Categories []string `json:"categories,omitempty"` Extensions ext.Extensions `json:"extensions,omitempty"` Custom map[string]string `json:"custom,omitempty"` Items []*Item `json:"items"` FeedType string `json:"feedType"` FeedVersion string `json:"feedVersion"` }
Feed is the universal Feed type that atom.Feed and rss.Feed gets translated to. It represents a web feed.
func (f Feed) String() string
type FeedType int
FeedType represents one of the possible feed types that we can detect.
const ( // FeedTypeUnknown represents a feed that could not have its // type determiend. FeedTypeUnknown FeedType = iota // FeedTypeAtom repesents an Atom feed FeedTypeAtom // FeedTypeRSS represents an RSS feed FeedTypeRSS )
func DetectFeedType(feed io.Reader) FeedType
DetectFeedType attempts to determine the type of feed by looking for specific xml elements unique to the various feed types.
▹ Example
type HTTPError struct { StatusCode int Status string }
HTTPError represents an HTTP error returned by a server.
func (err HTTPError) Error() string
type Image struct { URL string `json:"url,omitempty"` Title string `json:"title,omitempty"` }
Image is an image that is the artwork for a given feed or item.
type Item struct { Title string `json:"title,omitempty"` Description string `json:"description,omitempty"` Content string `json:"content,omitempty"` Link string `json:"link,omitempty"` Updated string `json:"updated,omitempty"` UpdatedParsed *time.Time `json:"updatedParsed,omitempty"` Published string `json:"published,omitempty"` PublishedParsed *time.Time `json:"publishedParsed,omitempty"` Author *Person `json:"author,omitempty"` GUID string `json:"guid,omitempty"` Image *Image `json:"image,omitempty"` Categories []string `json:"categories,omitempty"` Enclosures []*Enclosure `json:"enclosures,omitempty"` Extensions ext.Extensions `json:"extensions,omitempty"` Custom map[string]string `json:"custom,omitempty"` }
Item is the universal Item type that atom.Entry and rss.Item gets translated to. It represents a single entry in a given feed.
type Parser struct { AtomTranslator Translator RSSTranslator Translator Client *http.Client // contains filtered or unexported fields }
Parser is a universal feed parser that detects a given feed type, parsers it, and translates it to the universal feed type.
func NewParser() *Parser
NewParser creates a universal feed parser.
func (f *Parser) Parse(feed io.Reader) (*Feed, error)
Parse parses a RSS or Atom feed into the universal gofeed.Feed. It takes an io.Reader which should return the xml content.
▹ Example
func (f *Parser) ParseString(feed string) (*Feed, error)
ParseString parses a feed XML string and into the universal feed type.
▹ Example
func (f *Parser) ParseURL(feedURL string) (feed *Feed, err error)
ParseURL fetches the contents of a given url and attempts to parse the response into the universal feed type.
▹ Example
type Person struct { Name string `json:"name,omitempty"` Email string `json:"email,omitempty"` }
Person is an individual specified in a feed (e.g. an author)
type Translator interface { Translate(feed interface{}) (*Feed, error) }
Translator converts a particular feed (atom.Feed or rss.Feed) into the generic Feed struct