rss

package
v6.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

View Source
const (
	RSSTimeFormat = "Mon, 02 Jan 2006 15:04:05 -0700"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category struct {
	Domain string `xml:"domain,attr"`
	Value  string `xml:",chardata"`
}

type Channel

type Channel struct {
	// Required elements
	Title       string `xml:"title"`
	Link        string `xml:"link"`
	Description string `xml:"description"`

	// Optional elements
	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"`
	Generator      string     `xml:"generator,omitempty"`
	Docs           string     `xml:"docs,omitempty"`
	Categories     []Category `xml:"category,omitempty"`
	TTL            int        `xml:"ttl,omitempty"`
	Image          *Image     `xml:"image,omitempty"`
	Items          []*Item    `xml:"item,omitempty"`
}

func NewChannel

func NewChannel(title, link, description string) *Channel

NewChannel creates a new channel.

Title represents 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.

Link is the URL to the HTML website corresponding to the channel.

Description is the phrase or sentence describing the channel.

func (*Channel) AddCategory

func (c *Channel) AddCategory(value, domain string) *Channel

AddCategory specifies one or more categories that the channel belongs to. It follows the same rules as the <item>-level category element.

func (*Channel) AddItem

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

AddItem adds an item to the channel.

func (*Channel) SetCopyright

func (c *Channel) SetCopyright(copyright string) *Channel

SetCopyright sets the copyright notice for content in the channel.

func (*Channel) SetDocs

func (c *Channel) SetDocs(docs string) *Channel

SetDocs indicates the documentation of the format used in the RSS file.

func (*Channel) SetGenerator

func (c *Channel) SetGenerator(generator string) *Channel

SetGenerator indicates the program used to generate the channel.

func (*Channel) SetImage

func (c *Channel) SetImage(image *Image) *Channel

SetImage specifies a GIF, JPEG or PNG image that can be displayed with the channel.

func (*Channel) SetLanguage

func (c *Channel) SetLanguage(language string) *Channel

SetLanguage sets the language the channel is written in.

Examples: en-us, it-it, en-gb, en-ca, fr-fr, de-de, ja-jp, zh-cn, zh-tw, etc.

func (*Channel) SetLastBuildDate

func (c *Channel) SetLastBuildDate(lastBuildDate time.Time, loc *time.Location) *Channel

SetLastBuildDate indicates the last time the content of the channel changed. The time location must be specified so the date time string can be correctly formatted according to the RSS specification.

func (*Channel) SetManagingEditor

func (c *Channel) SetManagingEditor(email, name string) *Channel

SetManagingEditor sets the email address for person responsible for editorial content.

func (*Channel) SetPubDate

func (c *Channel) SetPubDate(pubDate time.Time, loc *time.Location) *Channel

SetPubDate indicates when the channel was last updated. The time location must be specified so the date time string can be correctly formatted according to the RSS specification.

func (*Channel) SetTTL

func (c *Channel) SetTTL(ttl int) *Channel

SetTTL specifies the number of minutes that indicates how long a channel can be cached before refreshing from the source.

func (*Channel) SetWebMaster

func (c *Channel) SetWebMaster(email, name string) *Channel

SetWebMaster sets the email address for person responsible for technical issues relating to channel.

type Enclosure

type Enclosure struct {
	URL      string `xml:"url,attr"`
	Length   int    `xml:"length,attr"`
	MimeType string `xml:"type,attr"`
}

type Feed

type Feed struct {
	XMLName xml.Name `xml:"rss"`
	Version string   `xml:"version,attr"`
	Channel *Channel `xml:"channel"`
}

func NewFeed

func NewFeed(channel *Channel) *Feed

NewFeed creates a new RSS feed.

func (*Feed) ToXML

func (f *Feed) ToXML(indent, includeHeader bool) ([]byte, error)

ToXML returns the XML representation of the feed.

type GUID

type GUID struct {
	IsPermaLink bool   `xml:"isPermaLink,attr"`
	Value       string `xml:",chardata"`
}

type Image

type Image struct {
	// Required elements
	URL   string `xml:"url,omitempty"`
	Title string `xml:"title,omitempty"`
	Link  string `xml:"link,omitempty"`

	// Optional elements
	Width       int    `xml:"width,omitempty"`
	Height      int    `xml:"height,omitempty"`
	Description string `xml:"description,omitempty"`
}

func NewImage

func NewImage(url, title, link string) *Image

NewImage specifies a GIF, JPEG or PNG image that can be displayed with the channel. URL is the URL of a GIF, JPEG or PNG image that represents the channel. Title describes the image, it's used in the ALT attribute of the HTML <img> tag when the channel is rendered in HTML. Link is the URL of the site, when the channel is rendered, the image is a link to the site.

func (*Image) SetDescription

func (i *Image) SetDescription(description string) *Image

SetDescription specifies the text that is included in the TITLE attribute of the link formed around the image in the HTML rendering.

func (*Image) SetHeight

func (i *Image) SetHeight(height int) *Image

SetHeight specifies the height of the image in pixels.

func (*Image) SetWidth

func (i *Image) SetWidth(width int) *Image

SetWidth specifies the width of the image in pixels.

type Item

type Item struct {
	// All elements of an item are optional,
	// however at least one of title or
	// description must be present.
	Title       string `xml:"title,omitempty"`
	Description string `xml:"description,omitempty"`

	// Optional elements
	Link       string     `xml:"link,omitempty"`
	Author     string     `xml:"author,omitempty"`
	Comments   string     `xml:"comments,omitempty"`
	PubDate    string     `xml:"pubDate,omitempty"`
	GUID       *GUID      `xml:"guid,omitempty"`
	Enclosure  *Enclosure `xml:"enclosure,omitempty"`
	Categories []Category `xml:"category,omitempty"`
}

func NewItemWithDescription

func NewItemWithDescription(description string) *Item

NewItemWithDescription creates an item which represents a "story" -- much like a story in a newspaper or magazine; if so its description is a synopsis of the story, and the link points to the full story. An item may also be complete in itself, if so, the description contains the text (entity-encoded HTML is allowed), and the link and title may be omitted. All elements of an item are optional, however at least one of title or description must be present.

func NewItemWithTitle

func NewItemWithTitle(title string) *Item

NewItemWithTitle creates an item which represents a "story" -- much like a story in a newspaper or magazine; if so its description is a synopsis of the story, and the link points to the full story. An item may also be complete in itself, if so, the description contains the text (entity-encoded HTML is allowed), and the link and title may be omitted. All elements of an item are optional, however at least one of title or description must be present.

func (*Item) AddCategory

func (i *Item) AddCategory(value, domain string) *Item

AddCategory includes the item in one or more categories. More than one category may be specified by including multiple category elements.

It has one optional attribute, domain, a string that identifies a categorization taxonomy.

The value of the element is a forward-slash-separated string that identifies a hierarchic location in the indicated taxonomy. Processors may establish conventions for the interpretation of categories.

func (*Item) SetAuthor

func (i *Item) SetAuthor(email, name string) *Item

SetAuthor sets the email address of the author of the item.

func (*Item) SetComments

func (i *Item) SetComments(comments string) *Item

SetComments sets the URL of a page for comments relating to the item.

func (*Item) SetDescription

func (i *Item) SetDescription(description string) *Item

SetDescription sets the item synopsis.

func (*Item) SetEnclosure

func (i *Item) SetEnclosure(url string, length int, mimeType string) *Item

SetEnclosure describes a media object that is attached to the item. It has three required attributes. url says where the enclosure is located, length says how big it is in bytes, and type says what its type is, a standard MIME type.

Example:

<enclosure url="http://www.scripting.com/mp3s/weatherReportSuite.mp3" length="12216320" type="audio/mpeg" />

func (*Item) SetGUID

func (i *Item) SetGUID(value string, isPermaLink bool) *Item

SetGUID sets a string that uniquely identifies the item.

func (i *Item) SetLink(link string) *Item

SetLink sets the URL of the item.

func (*Item) SetPubDate

func (i *Item) SetPubDate(pubDate time.Time, loc *time.Location) *Item

SetPubDate indicates when the item was published. If it's a date in the future, aggregators may choose to not display the item until that date. The time location must be specified so the date time string can be correctly formatted according to the RSS specification.

func (*Item) SetTitle

func (i *Item) SetTitle(title string) *Item

SetTitle sets the title of the item.

Jump to

Keyboard shortcuts

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