Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrFeedTypeNotDetected = errors.New("Failed to detect feed type")
ErrFeedTypeNotDetected is returned when the detection system can not figure out the Feed format
Functions ¶
This section is empty.
Types ¶
type DefaultAtomTranslator ¶
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 (*DefaultAtomTranslator) Translate ¶
func (t *DefaultAtomTranslator) Translate(feed interface{}) (*Feed, error)
Translate converts an Atom feed into the universal feed type.
type DefaultJSONTranslator ¶
type DefaultJSONTranslator struct{}
DefaultJSONTranslator converts an json.Feed struct into the generic Feed struct.
This default implementation defines a set of mapping rules between json.Feed -> Feed for each of the fields in Feed.
func (*DefaultJSONTranslator) Translate ¶
func (t *DefaultJSONTranslator) Translate(feed interface{}) (*Feed, error)
Translate converts an JSON feed into the universal feed type.
type DefaultRSSTranslator ¶
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 (*DefaultRSSTranslator) Translate ¶
func (t *DefaultRSSTranslator) Translate(feed interface{}) (*Feed, error)
Translate converts an RSS feed into the universal feed type.
type Enclosure ¶
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 ¶
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"` DublinCoreExt *ext.DublinCoreExtension `json:"dcExt,omitempty"` ITunesExt *ext.ITunesFeedExtension `json:"itunesExt,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. Sorting with sort.Sort will order the Items by oldest to newest publish time.
type FeedType ¶
type FeedType int
FeedType represents one of the possible feed types that we can detect.
func DetectFeedType ¶
DetectFeedType attempts to determine the type of feed by looking for specific xml elements unique to the various feed types.
Example ¶
package main import ( "fmt" "strings" "github.com/skuzzymiglet/gofeed" ) func main() { feedData := `<rss version="2.0"> <channel> <title>Sample Feed</title> </channel> </rss>` feedType := gofeed.DetectFeedType(strings.NewReader(feedData)) if feedType == gofeed.FeedTypeRSS { fmt.Println("Wow! This is an RSS feed!") } }
Output:
type 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"` DublinCoreExt *ext.DublinCoreExtension `json:"dcExt,omitempty"` ITunesExt *ext.ITunesItemExtension `json:"itunesExt,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 ¶
type Parser struct { AtomTranslator Translator RSSTranslator Translator JSONTranslator Translator // 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 (*Parser) Parse ¶
Parse parses a RSS or Atom or JSON feed into the universal gofeed.Feed. It takes an io.Reader which should return the xml/json content.
Example ¶
package main import ( "fmt" "strings" "github.com/skuzzymiglet/gofeed" ) func main() { feedData := `<rss version="2.0"> <channel> <title>Sample Feed</title> </channel> </rss>` fp := gofeed.NewParser() feed, err := fp.Parse(strings.NewReader(feedData)) if err != nil { panic(err) } fmt.Println(feed.Title) }
Output:
func (*Parser) ParseString ¶
ParseString parses a feed XML string and into the universal feed type.
Example ¶
package main import ( "fmt" "github.com/skuzzymiglet/gofeed" ) func main() { feedData := `<rss version="2.0"> <channel> <title>Sample Feed</title> </channel> </rss>` fp := gofeed.NewParser() feed, err := fp.ParseString(feedData) if err != nil { panic(err) } fmt.Println(feed.Title) }
Output:
type Translator ¶
Translator converts a particular feed (atom.Feed or rss.Feed of json.Feed) into the generic Feed struct