rssutil

package
v0.0.0-...-cdd6f12 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2019 License: GPL-3.0, GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTTL = time.Duration(20) * time.Minute

DefaultTTL is the TTL who will be used when when there's no TTL specified, e.g. Serve was called without forceTTL when RSS has no TTL attribute.

Variables

This section is empty.

Functions

func Serve

func Serve(source string, forceTTL time.Duration, userData interface{},
	onRSSFeedInit RSSFeedInitNotifier, onRSSUpdate RSSUpdateNotifier) (err error)

Serve starts the default RSS service to keep the content update automatically in background in duration forceTTL. It always return an error.

func Stop

func Stop()

Stop send a stop-signal to stop the default RSS service.

Types

type RFC822

type RFC822 time.Time

func (RFC822) After

func (r RFC822) After(t RFC822) bool

After reports whether the RFC822 instant r is after t.

func (RFC822) Equal

func (r RFC822) Equal(t RFC822) bool

func (RFC822) Format

func (r RFC822) Format(layout string) string

func (RFC822) IsZero

func (r RFC822) IsZero() bool

IsZero reports whether r represents the zero time instant, January 1, year 1, 00:00:00 UTC.

func (*RFC822) MarshalJSON

func (r *RFC822) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshal interface.

func (RFC822) String

func (r RFC822) String() string

func (*RFC822) UnmarshalXML

func (r *RFC822) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the xml.Unmarshal interface.

type RSS

type RSS struct {
	Version string     `xml:"version,attr" json:"version"`
	Channel RSSChannel `xml:"channel"      json:"channel"`
}

RSS is a Web content syndication format.

Its name is an acronym for Really Simple Syndication.

RSS is a dialect of XML. All RSS files must conform to the XML 1.0 specification, as published on the World Wide Web Consortium (W3C) website.

A summary of RSS version history.

At the top level, a RSS document is a <rss> element, with a mandatory attribute called version, that specifies the version of RSS that the document conforms to. If it conforms to this specification, the version attribute must be 2.0.

Subordinate to the <rss> element is a single <channel> element, which contains information about the channel (metadata) and its contents.

func (RSS) String

func (rss RSS) String() string

type RSSCategories

type RSSCategories []RSSCategory

func (RSSCategories) Equal

func (c RSSCategories) Equal(t RSSCategories) bool

type RSSCategory

type RSSCategory struct {
	Category string `xml:",chardata" json:"category"`

	Domain string `xml:"domain,attr,omitempty" json:"domain,omitempty"`
}

RSSCategory is an optional sub-element of RSSChannel/RSSItem.

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. Two examples are provided below:

<category>Grateful Dead</category>

<category domain="http://www.fool.com/cusips">MSFT</category>

You may include as many category elements as you need to, for different domains, and to have an item cross-referenced in different parts of the same domain.

func (RSSCategory) Equal

func (c RSSCategory) Equal(t RSSCategory) bool

func (RSSCategory) String

func (c RSSCategory) String() string

type RSSChannel

type RSSChannel 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.
	//
	// Sample:
	//   GoUpstate.com News Headlines
	Title string `xml:"title" json:"title"`

	// The URL to the HTML website corresponding to the channel.
	//
	// Sample:
	//   http://www.goupstate.com/
	Link string `xml:"link" json:"link"`

	// Phrase or sentence describing the channel.
	//
	// Sample:
	//   The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site.
	Description string `xml:"description" json:"description"`

	// 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, is [here](https://cyber.harvard.edu/rss/languages.html).
	// You may also use [values defined](https://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes)
	// by the W3C.
	//
	// Sample:
	//   en-us
	Language string `xml:"language,omitempty" json:"language,omitempty"`

	// Copyright notice for content in the channel.
	//
	// Sample:
	//   Copyright 2002, Spartanburg Herald-Journal
	Copyright string `xml:"copyright,omitempty" json:"copyright,omitempty"`

	// Email address for person responsible for editorial content.
	//
	// Sample:
	//   geo@herald.com (George Matesky)
	ManagingEditor string `xml:"managingEditor,omitempty" json:"managing_editor,omitempty"`

	// Email address for person responsible for technical issues relating to channel.
	//
	// Sample:
	//   betty@herald.com (Betty Guernsey)
	WebMaster string `xml:"webMaster,omitempty" json:"webmaster,omitempty"`

	// 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](http://asg.web.cmu.edu/rfc/rfc822.html),
	// with the exception that the year may be expressed with two
	// characters or four characters (four preferred).
	//
	// Sample:
	//   Sat, 07 Sep 2002 00:00:01 GMT
	PubDate *RFC822 `xml:"pubDate,omitempty" json:"pub_date,omitempty"`

	// The last time the content of the channel changed.
	//
	// Sample:
	//   Sat, 07 Sep 2002 09:42:31 GMT
	LastBuildDate *RFC822 `xml:"lastBuildDate,omitempty" json:"last_build_date,omitempty"`

	// Specify one or more categories that the channel belongs to.
	// Follows the same rules as the <item>-level
	// [category](https://cyber.harvard.edu/rss/rss.html#ltcategorygtSubelementOfLtitemgt)
	// element. More [info](https://cyber.harvard.edu/rss/rss.html#syndic8).
	//
	// Sample:
	//   <category>Newspapers</category>
	Categories RSSCategories `xml:"category,omitempty" json:"category,omitempty"`

	// A string indicating the program used to generate the channel.
	//
	// Sample:
	//   MightyInHouse Content System v2.3
	Generator string `xml:"generator,omitempty" json:"generator,omitempty"`

	// A URL that points to the documentation for the format used in the
	// RSS file. It's probably a pointer to this page. It's for people
	// who might stumble across an RSS file on a Web server 25 years from
	// now and wonder what it is.
	//
	// Sample:
	//   http://blogs.law.harvard.edu/tech/rss
	Docs string `xml:"docs,omitempty" json:"docs,omitempty"`

	// Allows processes to register with a cloud to be notified of
	// updates to the channel, implementing a lightweight
	// publish-subscribe protocol for RSS feeds. More info
	// [here](https://cyber.harvard.edu/rss/rss.html#ltcloudgtSubelementOfLtchannelgt).
	//
	// Sample:
	//   <cloud domain="rpc.sys.com" port="80" path="/RPC2" registerProcedure="pingMe" protocol="soap"/>
	Cloud *RSSCloud `xml:"cloud,omitempty" json:"cloud,omitempty"`

	// TTL stands for time to live. It's a number of minutes that
	// indicates how long a channel can be cached before refreshing from
	// the source. More info [here](https://cyber.harvard.edu/rss/rss.html#ltttlgtSubelementOfLtchannelgt).
	//
	// Sample:
	//   <ttl>60</ttl>
	TTL int `xml:"ttl,omitempty" json:"ttl,omitempty"`

	// Specifies a GIF, JPEG or PNG image that can be displayed with the
	// channel.
	// More info [here](https://cyber.harvard.edu/rss/rss.html#ltimagegtSubelementOfLtchannelgt).
	Image *RSSImage `xml:"image,omitempty" json:"image,omitempty"`

	// The [PICS](https://www.w3.org/PICS/) rating for the channel.
	Rating string `xml:"rating,omitempty" json:"rating,omitempty"`

	// Specifies a text input box that can be displayed with the channel.
	// More info [here](https://cyber.harvard.edu/rss/rss.html#lttextinputgtSubelementOfLtchannelgt).
	TextInput *RSSTextInput `xml:"textInput,omitempty" json:"text_input,omitempty"`

	// A hint for aggregators telling them which hours they can skip.
	// More info [here](https://cyber.harvard.edu/rss/skipHoursDays.html#skiphours).
	SkipHours []int `xml:"skipHours>hour,omitempty" json:"skip_hours,omitempty"`

	// A hint for aggregators telling them which days they can skip.
	// More info [here](https://cyber.harvard.edu/rss/skipHoursDays.html#skipdays).
	SkipDays []time.Weekday `xml:"skipDays>day,omitempty" json:"skip_days,omitempty"`

	Items RSSItems `xml:"item,omitempty" json:"items,omitempty"`
}

func (RSSChannel) String

func (c RSSChannel) String() string

type RSSCloud

type RSSCloud struct {
	Domain            string `xml:"domain,attr" json:"domain"`
	Port              int    `xml:"port,attr" json:"port"`
	Path              string `xml:"path,attr" json:"path"`
	RegisterProcedure string `xml:"registerProcedure,attr" json:"register_procedure"`
	Protocol          string `xml:"protocol,attr" json:"protocol"`
}

RSSCloud is an optional sub-element of RSSChannel. It specifies a web service that supports the RSSCloud interface which can be implemented in HTTP-POST, XML-RPC or SOAP 1.1.

Its purpose is to allow processes to register with a cloud to be notified of updates to the channel, implementing a lightweight publish-subscribe protocol for RSS feeds.

<cloud domain="rpc.sys.com" port="80" path="/RPC2" registerProcedure="myCloud.rssPleaseNotify" protocol="xml-rpc" />

In this example, to request notification on the channel it appears in, you would send an XML-RPC message to rpc.sys.com on port 80, with a path of /RPC2. The procedure to call is myCloud.rssPleaseNotify.

A full explanation of this element and the RSSCloud interface is [here](https://cyber.harvard.edu/rss/soapMeetsRss.html#rsscloudInterface).

func (RSSCloud) Equal

func (c RSSCloud) Equal(t RSSCloud) bool

func (RSSCloud) String

func (c RSSCloud) String() string

type RSSEnclosure

type RSSEnclosure struct {
	URL    string `xml:"url,attr"    json:"url"`
	Length int    `xml:"length,attr" json:"length"`
	Type   string `xml:"type,attr"   json:"type"`
}

RSSEnclosure is an optional sub-element of RSSItem.

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.

The url must be an http url.

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

A use-case narrative for this element is [here](http://www.thetwowayweb.com/payloadsforrss).

func (RSSEnclosure) Equal

func (ec RSSEnclosure) Equal(t RSSEnclosure) bool

func (RSSEnclosure) String

func (ec RSSEnclosure) String() string

type RSSFeedInitNotifier

type RSSFeedInitNotifier func(items RSSItems, userData interface{})

RSSFeedInitNotifier represents a notifier who will be triggered at initial RSS content update. The initial update which means the first time RSS content get updated. All the RSS items will be sent to this notifier.

type RSSGUID

type RSSGUID struct {
	GUID        string `xml:",chardata" json:"guid"`
	IsPermaLink bool   `xml:"isPermaLink,attr" json:"is_perma_link"`
}

func (RSSGUID) Equal

func (g RSSGUID) Equal(t RSSGUID) bool

func (RSSGUID) String

func (g RSSGUID) String() string

type RSSImage

type RSSImage struct {

	// URL is the URL of a GIF, JPEG or PNG image that represents the
	// Channel.
	URL string `xml:"url" json:"url"`

	// Title describes the image, it's used in the ALT attribute of the
	// HTML <img> tag when the channel is rendered in HTML.
	Title string `xml:"title" json:"title"`

	// Link is the URL of the site, when the channel is rendered, the
	// image is a link to the site. (Note, in practice the image Title
	// and Link should have the same value as the Channel's Title and Link.
	Link string `xml:"link" json:"link"`

	// Width is an optional elements, in numbers, indicating the width of
	// the image in pixels.
	//
	// Maximum value for width is 144, default value is 88.
	Width int `xml:"width,omitempty" json:"width,omitempty"`

	// Height is an optional elements, in numbers, indicating the height
	// of the image in pixels.
	//
	// Maximum value for height is 400, default value is 31.
	Height int `xml:"height,omitempty" json:"height,omitempty"`

	// Description is an optional elements, which contains text that is
	// included in the TITLE attribute of the link formed around the
	// image in the HTML rendering.
	Description string `xml:"description,omitempty" json:"description,omitempty"`
}

RSSImage is an optional sub-element of RSSChannel, which contains three required and three optional sub-elements.

func (RSSImage) Equal

func (img RSSImage) Equal(t RSSImage) bool

func (RSSImage) String

func (img RSSImage) String() string

type RSSItem

type RSSItem struct {
	// The title of the item.
	//
	// Sample:
	//   Venice Film Festival Tries to Quit Sinking
	Title string `xml:"title,omitempty" json:"title,omitempty"`

	// The URL of the item.
	//
	// Sample:
	//   http://nytimes.com/2004/12/07FEST.html
	Link string `xml:"link,omitempty" json:"link,omitempty"`

	// The item synopsis.
	//
	// Sample:
	//   Some of the most heated chatter at the Venice Film Festival this
	//   week was about the way that the arrival of the stars at the
	//   Palazzo del Cinema was being staged.
	Description string `xml:"description,omitempty" json:"description,omitempty"`

	// Email address of the author of the item.
	// [More](https://cyber.harvard.edu/rss/rss.html#ltauthorgtSubelementOfLtitemgt).
	//
	// Sample:
	//   oprah@oxygen.net
	Author string `xml:"author,omitempty" json:"author,omitempty"`

	// Includes the item in one or more categories.
	// [More](https://cyber.harvard.edu/rss/rss.html#ltcategorygtSubelementOfLtitemgt).
	Categories RSSCategories `xml:"category,omitempty" json:"category,omitempty"`

	// URL of a page for comments relating to the item.
	// [More](https://cyber.harvard.edu/rss/rss.html#ltcommentsgtSubelementOfLtitemgt).
	//
	// Sample:
	//   http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290
	Comments string `xml:"comments,omitempty" json:"comments,omitempty"`

	// Describes a media object that is attached to the item.
	// [More](https://cyber.harvard.edu/rss/rss.html#ltenclosuregtSubelementOfLtitemgt).
	Enclosure *RSSEnclosure `xml:"enclosure,omitempty" json:"enclosure,omitempty"`

	// A string that uniquely identifies the item.
	// [More](https://cyber.harvard.edu/rss/rss.html#ltguidgtSubelementOfLtitemgt).
	//
	// Sample:
	//   http://inessential.com/2002/09/01.php#a2
	GUID *RSSGUID `xml:"guid,omitempty" json:"guid,omitempty"`

	// Indicates when the item was published.
	// [More](https://cyber.harvard.edu/rss/rss.html#ltpubdategtSubelementOfLtitemgt).
	//
	// Sample:
	//   Sun, 19 May 2002 15:21:36 GMT
	PubDate *RFC822 `xml:"pubDate,omitempty" json:"pub_date,omitempty"`

	// The RSS channel that the item came from.
	// [More](https://cyber.harvard.edu/rss/rss.html#ltsourcegtSubelementOfLtitemgt).
	//
	// Sample:
	//   <source url="http://www.tomalak.org/links2.xml">Tomalak's Realm</source>
	Source *RSSSource `xml:"source,omitempty" json:"source,omitempty"`
}

A channel may contain any number of <item>s. An item may represent 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; see [examples](https://cyber.harvard.edu/rss/encodingDescriptions.html)), 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 (RSSItem) Equal

func (it RSSItem) Equal(t RSSItem) bool

func (RSSItem) MD5

func (it RSSItem) MD5() string

func (RSSItem) String

func (it RSSItem) String() string

type RSSItems

type RSSItems []RSSItem

func (RSSItems) Equal

func (it RSSItems) Equal(t RSSItems) bool

type RSSSource

type RSSSource struct {
	Source string `xml:",chardata" json:"source"`
	URL    string `xml:"url,attr" json:"url"`
}

RSSSource is an optional sub-element of RSSItem.

Its value is the name of the RSSChannel that the item came from, derived from its <title>. It has one required attribute, url, which links to the XMLization of the source.

<source url="http://www.tomalak.org/links2.xml">Tomalak's Realm</source>

The purpose of this element is to propagate credit for links, to publicize the sources of news items. It can be used in the Post command of an aggregator. It should be generated automatically when forwarding an item from an aggregator to a weblog authoring tool.

func (RSSSource) Equal

func (s RSSSource) Equal(t RSSSource) bool

func (RSSSource) String

func (s RSSSource) String() string

type RSSTextInput

type RSSTextInput struct {

	// The label of the Submit button in the text input area.
	Title string `xml:"title" json:"title"`

	// Explains the text input area.
	Description string `xml:"description" json:"description"`

	// The name of the text object in the text input area.
	Name string `xml:"name" json:"name"`

	// The URL of the CGI script that processes text input requests.
	Link string `xml:"link" json:"link"`
}

RSSTextInput is an optional sub-element of RSSChannel, which contains four required sub-elements.

The purpose of the TextInput element is something of a mystery. You can use it to specify a search engine box. Or to allow a reader to provide feedback. Most aggregators ignore it.

func (RSSTextInput) Equal

func (ti RSSTextInput) Equal(t RSSTextInput) bool

func (RSSTextInput) String

func (ti RSSTextInput) String() string

type RSSUpdateNotifier

type RSSUpdateNotifier func(items RSSItems, userData interface{})

RSSUpdateNotifier represents a notifier who will be triggered at the time RSS content updated. All the newly created and changed RSS items will be sent to this notifier.

type RSSUtil

type RSSUtil struct {
	FeedInitNotifier RSSFeedInitNotifier
	UpdateNotifier   RSSUpdateNotifier
	// contains filtered or unexported fields
}

func (*RSSUtil) Feed

func (ru *RSSUtil) Feed(source string) error

Feed feeds RSS content from source.

func (*RSSUtil) Serve

func (ru *RSSUtil) Serve(forceTTL time.Duration)

Serve starts the default RSS service to keep the content update automatically in background in duration forceTTL.

func (*RSSUtil) Stop

func (ru *RSSUtil) Stop()

Stop send a stop-signal to stop the default RSS service.

func (*RSSUtil) Update

func (ru *RSSUtil) Update() error

Update updates RSS content from URL.

Jump to

Keyboard shortcuts

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