syndfeed: github.com/zhengchun/syndfeed Index | Examples | Files

package syndfeed

import "github.com/zhengchun/syndfeed"

Index

Examples

Package Files

atom.go date.go feed.go plugin.go rss.go

func RegisterExtensionModule Uses

func RegisterExtensionModule(nsURL string, m Module)

RegisterExtensionModule registers Module with the specified XML namespace.

type Atom Uses

type Atom struct{}

Atom is an Atom feed parser. https://validator.w3.org/feed/docs/rfc4287.html

The following example is parse an Atom feed.

Code:

f, err := os.Open("./a.atom")
if err != nil {
    panic(err)
}
feed, err := ParseAtom(f)
if err != nil {
    panic(err)
}
fmt.Println(feed.Title)
fmt.Println(feed.Version)

func (*Atom) Parse Uses

func (a *Atom) Parse(r io.Reader) (*Feed, error)

Parse parses an atom feed.

type ElementExtension Uses

type ElementExtension struct {
    Name, Namespace, Value string
}

ElementExtension is an syndication element extension.

type Feed Uses

type Feed struct {
    Authors      []*Person
    BaseURL      string
    Categories   []string
    Contributors []*Person
    Copyright    string
    Namespace    map[string]string // map[namespace-prefix]namespace-url
    Description  string
    Generator    string
    Id           string
    ImageURL     string
    Items        []*Item
    Language     string
    // LastUpdatedTime is the feed was last updated time.
    LastUpdatedTime   time.Time
    Title             string
    Links             []*Link
    Version           string
    ElementExtensions []*ElementExtension
}

Feed is top-level feed object, <feed> in Atom 1.0 and <rss> in RSS 2.0.

func LoadURL Uses

func LoadURL(url string) (*Feed, error)

LoadURL loads a syndication feed URL.

func Parse Uses

func Parse(r io.Reader) (*Feed, error)

Parse parses a syndication feed(RSS,Atom).

Code:

s := `<?xml version="1.0" encoding="UTF-8" ?>
	<rss version="2.0">
	<channel>
	 <title>RSS Title</title>
	 <description>This is an example of an RSS feed</description>
	 <link>http://www.example.com/main.html</link>
	 <lastBuildDate>Mon, 06 Sep 2010 00:01:00 +0000 </lastBuildDate>
	 <pubDate>Sun, 06 Sep 2009 16:20:00 +0000</pubDate>
	 <ttl>1800</ttl>	
	 <item>
	  <title>Example entry</title>
	  <description>Here is some text containing an interesting description.</description>
	  <link>http://www.example.com/blog/post/1</link>
	  <guid isPermaLink="false">7bd204c6-1655-4c27-aeee-53f933c5395f</guid>
	  <pubDate>Sun, 06 Sep 2009 16:20:00 +0000</pubDate>
	 </item>	
	</channel>
	</rss>`
feed, err := Parse(strings.NewReader(s))
if err != nil {
    panic(err)
}
fmt.Println(feed.Title)
fmt.Println(feed.Version)
fmt.Println(len(feed.Items))

func ParseAtom Uses

func ParseAtom(r io.Reader) (*Feed, error)

ParseAtom parses Atom feed from the specified io.Reader r.

func ParseRSS Uses

func ParseRSS(r io.Reader) (*Feed, error)

ParseRSS parses RSS feed from the specified io.Reader r.

type Item Uses

type Item struct {
    BaseURL      string
    Authors      []*Person
    Contributors []*Person
    Categories   []string
    Content      string
    Copyright    string
    Id           string
    // LastUpdatedTime is the feed item last updated time.
    LastUpdatedTime time.Time
    Links           []*Link
    // PublishDate is the feed item publish date.
    PublishDate       time.Time
    Summary           string
    Title             string
    ElementExtensions []*ElementExtension
}

Item is a feed item.

type Link struct {
    MediaType string
    URL       string
    Title     string
    RelType   string
}

Link represents a link within a syndication feed or item.

type Module Uses

type Module interface {
    ParseElement(n *xmlquery.Node, v interface{})
}

Module is an interface is used to handle an extension element which not specified in either the Atom 1.0 or RSS 2.0 specifications.

type ModuleHandlerFunc Uses

type ModuleHandlerFunc func(*xmlquery.Node, interface{})

ModuleHandlerFunc is a utility function that wrapper a function as Module object.

func (ModuleHandlerFunc) ParseElement Uses

func (f ModuleHandlerFunc) ParseElement(n *xmlquery.Node, v interface{})

type Person Uses

type Person struct {
    Name  string
    URL   string
    Email string
}

Person is an author or contributor of the feed content.

type RSS Uses

type RSS struct{}

RSS is an RSS feed parser. https://validator.w3.org/feed/docs/rss2.html

The following example is parse an RSS feed.

Code:

f, err := os.Open("./a.rss")
if err != nil {
    panic(err)
}
feed, err := ParseRSS(f)
if err != nil {
    panic(err)
}
fmt.Println(feed.Title)
fmt.Println(feed.Version)

func (*RSS) Parse Uses

func (s *RSS) Parse(r io.Reader) (*Feed, error)

Parse parses an Rss feed.

Package syndfeed imports 7 packages (graph) and is imported by 1 packages. Updated 2018-03-14. Refresh now. Tools for package owners.