gofeed: github.com/mmcdole/gofeed Index | Examples | Files | Directories

package gofeed

import "github.com/mmcdole/gofeed"

Index

Examples

Package Files

detector.go feed.go parser.go translator.go

Variables

var ErrFeedTypeNotDetected = errors.New("Failed to detect feed type")

ErrFeedTypeNotDetected is returned when the detection system can not figure out the Feed format

type DefaultAtomTranslator Uses

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 Uses

func (t *DefaultAtomTranslator) Translate(feed interface{}) (*Feed, error)

Translate converts an Atom feed into the universal feed type.

type DefaultRSSTranslator Uses

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 Uses

func (t *DefaultRSSTranslator) Translate(feed interface{}) (*Feed, error)

Translate converts an RSS feed into the universal feed type.

type Enclosure Uses

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 Uses

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.

func (Feed) String Uses

func (f Feed) String() string

type FeedType Uses

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 Uses

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.

Code:

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!")
}

type HTTPError Uses

type HTTPError struct {
    StatusCode int
    Status     string
}

HTTPError represents an HTTP error returned by a server.

func (HTTPError) Error Uses

func (err HTTPError) Error() string

type Image Uses

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 Uses

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 Uses

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 Uses

func NewParser() *Parser

NewParser creates a universal feed parser.

func (*Parser) Parse Uses

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.

Code:

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)

func (*Parser) ParseString Uses

func (f *Parser) ParseString(feed string) (*Feed, error)

ParseString parses a feed XML string and into the universal feed type.

Code:

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)

func (*Parser) ParseURL Uses

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.

Code:

fp := gofeed.NewParser()
feed, err := fp.ParseURL("http://feeds.twit.tv/twit.xml")
if err != nil {
    panic(err)
}
fmt.Println(feed.Title)

type Person Uses

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 Uses

type Translator interface {
    Translate(feed interface{}) (*Feed, error)
}

Translator converts a particular feed (atom.Feed or rss.Feed) into the generic Feed struct

Directories

PathSynopsis
atom
extensions
internal/shared
rss

Package gofeed imports 13 packages (graph) and is imported by 50 packages. Updated 2019-02-14. Refresh now. Tools for package owners.