moverss

package module
v0.0.0-...-8e4b6c9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2012 License: MIT Imports: 4 Imported by: 5

README

About

This is a library implementing an RSS feed generator for the Go programming language (http://golang.org/).

RSS (Rich Site Summary, or Really Simple Syndication) is a data format used to publish frequently updated works - such as blog entries, news headlines, audio and video - in a standardized format.

An RSS document (which is called a "feed", "web feed", or "channel") includes full or summarized text, plus metadata such as publishing dates and authorship.

Installing

$ go get github.com/baliw/moverss

Example

package main

import (
        "fmt"
        "github.com/baliw/moverss"
        "time"
)

func main() {
        c := moverss.ChannelFactory("Daniel's Channel", "http://RubyDeveloper.com/", "My Blog")
        c.SetPubDate(time.Now().UTC())

        c.AddItem(&moverss.Item{
                Title:       "Ruby Developer",
                Link:        "http://RubyDeveloper.com/",
                Description: "Ruby Developer",
                PubDate:     time.Now().UTC().Format(time.RFC1123),
        })
        c.AddItem(&moverss.Item{
                Title:       "Stack Overflow",
                Link:        "http://stackoverflow.com/users/1305696/daniel",
                Description: "Stack Overflow",
                PubDate:     time.Now().UTC().Format(time.RFC1123),
        })

        // Example: Using an item's SetPubDate method
        i := &moverss.Item{
                Title:       "LinkedIn",
                Link:        "http://www.linkedin.com/in/dangogh",
                Description: "My LinkedIn",
        }
        i.SetPubDate(time.Now().Unix())
        c.AddItem(i)

        fmt.Printf("%s\n\n", c.Publish())
        fmt.Printf("%s\n\n", c.PublishIndent())
}

Full documentation

Read it online or run

$ go doc github.com/baliw/moverss

Other Details

A few of the more obscure data points aren't implemented yet. I haven't seen feeds that implement them yet and I just want to make sure my implementation is good.

If you find this package useful and want to give back, I'd greatly appreciate a link to my Ruby developer site.

Documentation

Overview

Package moverss implements a rss 2.0 feed generator

RSS (Rich Site Summary, or Really Simple Syndication) is a data format used to publish frequently updated works - such as blog entries, news headlines, audio and video - in a standardized format.

An RSS document (which is called a "feed", "web feed", or "channel") includes full or summarized text, plus metadata such as publishing dates and authorship.

Spec located at: http://cyber.law.harvard.edu/rss/rss.html

Example Usage

c := moverss.ChannelFavtory("Ruby Developer", "http://RubyDeveloper.com/", "Ruby Developer Blog")
c.AddItem(&moverss.Item{
	Title:"Ruby Developer",
	Link:"http://RubyDeveloper.com/",
	Description:"My Blog",
	PubDate:time.Now().Unix(),
})
c.AddItem(&moverss.Item{
	Title:"Stack Overflow",
	Link:"http://stackoverflow.com/users/1305696/daniel",
	Description:"My Stack Overflow",
	PubDate:time.Now().Unix(),
})
c.AddItem(&moverss.Item{
	Title:"LinkedIn",
	Link:"http://www.linkedin.com/in/dangogh",
	Description:"My LinkedIn",
	PubDate:time.Now().Unix(),
})
output := c.Publish()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	// The name of the channel. It's how people refer to your service. If you have
	// an HTML website that contains the same information as your RSS file, the
	// title of your channel should be the same as the title of your website.
	Title string `xml:"title"`
	// The URL to the HTML website corresponding to the channel.
	Link string `xml:"link"`
	// Phrase or sentence describing the channel.
	Description string `xml:"description"`

	/////////////////////
	// Optional Fields //
	/////////////////////
	Language       string `xml:"language,omitempty"`
	Copyright      string `xml:"copyright,omitempty"`
	ManagingEditor string `xml:"managingEditor,omitempty"`
	WebMaster      string `xml:"webMaster,omitempty"`
	PubDate        string `xml:"pubDate,omitempty"`
	LastBuildDate  string `xml:"lastBuildDate,omitempty"`
	Category       string `xml:"category,omitempty"`
	Generator      string `xml:"generator,omitempty"`
	Docs           string `xml:"docs,omitempty"`
	TTL            string `xml:"ttl,omitempty"`
	SkipHours      string `xml:"skiphours,omitempty"`
	SkipDays       string `xml:"skipdays,omitempty"`

	Items []*Item

	// Stub member just for the xml generator.
	XMLName xml.Name `xml:"channel"`
}

func ChannelFactory

func ChannelFactory(Title string, Link string, Description string) *Channel

Use this to create the base channel of the rss feed. The Title is the name of the channel. It's how people refer to your service. If you have an HTML website that contains the same information as your RSS file, the title of your channel should be the same as the title of your website. The Link is the URL to the HTML website corresponding to the channel. The Description is the phrase or sentence describing the channel.

func (*Channel) AddItem

func (c *Channel) AddItem(i *Item)

Add an item to the feed list

func (*Channel) Publish

func (c *Channel) Publish() []byte

Publish the prepared rss feed without indentation

func (*Channel) PublishIndent

func (c *Channel) PublishIndent() []byte

Publish the prepared rss feed with indentation

func (*Channel) SetCategory

func (c *Channel) SetCategory(cat string)

(optional) Set the category field. The category field specifies one or more categories that the channel belongs to. It follows the same rules as the <item>-level category element. ( http://cyber.law.harvard.edu/rss/rss.html#syndic8 )

func (*Channel) SetCopyright

func (c *Channel) SetCopyright(Copyright string)

(optional) Set the channel's Copyright notice for content.

func (*Channel) SetDocs

func (c *Channel) SetDocs(docs string)

(optional) Set the docs field. The docs field is a URL that points to the documentation for the format used in the RSS file. It's usually a pointer to "http://cyber.law.harvard.edu/rss/rss.html". It's for people who might stumble across an RSS file on a Web server 25 years from now and wonder what it is.

func (*Channel) SetGenerator

func (c *Channel) SetGenerator(gen string)

(optional) Set generator field. The generator field is a string indicating the program used to generate the rss feed.

func (*Channel) SetLanguage

func (c *Channel) SetLanguage(Language string)

(optional) Set the channel's language field to the language the channel is written in. This allows aggregators to group all Italian language sites, for example, on a single page. A list of allowable values for this element, as provided by Netscape ( http://cyber.law.harvard.edu/rss/languages.html ). You may also use values defined by the W3C ( http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes )

func (*Channel) SetLastBuildDate

func (c *Channel) SetLastBuildDate(t interface{})

(optional) Set the lastBuildDate field. The lastBuildDate is The last time the content of the channel changed. This method can take an instance of time.Time, a Unix timestamp (int64) or a raw string.

func (*Channel) SetManagingEditor

func (c *Channel) SetManagingEditor(ManagingEditor string)

(optional) Set the channel's ManagingEditor field. The ManagingEditor field should contain the email address for the person responsible for editorial content.

func (*Channel) SetPubDate

func (c *Channel) SetPubDate(t interface{})

(optional) Set the channel's pubDate field. This method can take an instance of time.Time, a unix timestamp (int64) or a raw string to use for the date. The date should represent the publication date for the content in the channel. For example, the New York Times publishes on a daily basis, the publication date flips once every 24 hours. That's when the pubDate of the channel changes. All date-times in RSS conform to the Date and Time Specification of RFC 822, with the exception that the year may be expressed with two characters or four characters (four preferred).

func (*Channel) SetSkipDays

func (c *Channel) SetSkipDays(skipdays string)

(optional) Set the channel's skipHous field. The skipHours field is a hint for aggregators telling them which hours they can skip. More info: http://cyber.law.harvard.edu/rss/skipHoursDays.html#skiphours

func (*Channel) SetSkipHours

func (c *Channel) SetSkipHours(skiphours string)

(optional) Set the channel's skipDays field. The skipDays field is a hint for aggregators telling them which days they can skip. More info: http://cyber.law.harvard.edu/rss/skipHoursDays.html#skipdays

func (*Channel) SetTTL

func (c *Channel) SetTTL(ttl string)

(optional) Set the TTL field. TTL stands for time to live. It's a number of minutes that indicate how long a channel can be cached before refreshing from the source. More info here: http://cyber.law.harvard.edu/rss/rss.html#ltttlgtSubelementOfLtchannelgt

func (*Channel) SetWebMaster

func (c *Channel) SetWebMaster(WebMaster string)

(optional) Set the channel's webMaster field. The webmaster field should contain the email address of person responsible for technical issues relating to channel

type Item

type Item struct {
	//The URL of the item.
	Link string `xml:"link"`

	// The item synopsis.
	Description string `xml:"description"`

	// The title of the item.
	Title string `xml:"title,omitempty"`

	// Indicates when the item was published.
	// http://cyber.law.harvard.edu/rss/rss.html#ltpubdategtSubelementOfLtitemgt
	PubDate string `xml:"pubDate,omitempty"`

	// Email address of the author of the item.
	// http://cyber.law.harvard.edu/rss/rss.html#ltauthorgtSubelementOfLtitemgt
	Author string `xml:"author,omitempty"`

	// A string that uniquely identifies the item.
	// http://cyber.law.harvard.edu/rss/rss.html#ltguidgtSubelementOfLtitemgt
	Guid string `xml:"guid,omitempty"`

	// URL of a page for comments relating to the item.
	// http://cyber.law.harvard.edu/rss/rss.html#ltcommentsgtSubelementOfLtitemgt
	Comments string `xml:"comments,omitempty"`

	// Stub member just for the xml generator.
	XMLName xml.Name `xml:"item"`
}

func (*Item) SetPubDate

func (i *Item) SetPubDate(t interface{})

(optional) Set the item's pubDate field. This method can take an instance of time.Time, a unix timestamp (int64) or a raw string to use for the date. The date should represent the publication date for the content in the channel. For example, the New York Times publishes on a daily basis, the publication date flips once every 24 hours. That's when the pubDate of the channel changes. All date-times in RSS conform to the Date and Time Specification of RFC 822, with the exception that the year may be expressed with two characters or four characters (four preferred).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL