...

Package gofeed

import "github.com/mmcdole/gofeed"
Overview
Index
Examples
Subdirectories

Overview ▾

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 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"`
    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

func (f Feed) String() string

type FeedType

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

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

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

type HTTPError struct {
    StatusCode int
    Status     string
}

HTTPError represents an HTTP error returned by a server.

func (HTTPError) Error

func (err HTTPError) Error() string

type Image

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

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

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

func NewParser() *Parser

NewParser creates a universal feed parser.

func (*Parser) Parse

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

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

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

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

Example

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

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

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

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

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

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

Subdirectories

Name Synopsis
..
atom
cmd
ftest
extensions
rss