Documentation
¶
Overview ¶
Errors for the rss package.
The rss package provides utilities for handling RSS documents. It leverages the RSS 2.0 Specification for determining struct fields used during marshaling, unmarshaling, and validation.
See:
This package relies heavily on the encoding/xml package of the Go standard library:
See:
Some notes on parsing XML:
- The XMLName field name dictates the name of the XML element representing this struct.
- If the XML element contains character data, that data is accumulated in the first struct field that has tag ",chardata". The struct field may have type []byte or string. If there is no such field, the character data is discarded.
- A field with a tag including the "omitempty" option is omitted if the field value is empty. The empty values are false, 0, any nil pointer or interface value, and any array, slice, map, or string of length zero.
Utility functions for the rss package.
Index ¶
- Constants
- Variables
- func IsEmpty(s string) (bool, error)
- func IsNotEmpty(s string) (bool, error)
- func IsPositiveInteger(s string) (bool, error)
- func IsValidDate(s string) (bool, error)
- func IsValidMailAddress(s string) (bool, error)
- func IsValidURI(s string) (bool, error)
- func Validate(r RSSElement) (bool, []error)
- type Author
- type Category
- type Channel
- type Cloud
- type Comments
- type Copyright
- type Day
- type Description
- type Docs
- type Domain
- type Enclosure
- type GUID
- type Generator
- type Height
- type Hour
- type Image
- type IsPermaLink
- type Item
- type Language
- type LastBuildDate
- type Length
- type Link
- type ManagingEditor
- type Name
- type Path
- type Port
- type Protocol
- type PubDate
- type RSS
- type RSSElement
- type Rating
- type RegisterProcedure
- type SkipDays
- type SkipHours
- type Source
- type TTL
- type TextInput
- type Title
- type Type
- type URL
- type Version
- type WebMaster
- type Width
Constants ¶
const RSSVERSION = "2.0"
Variables ¶
var ErrEmptyValue = errors.New("Element must not have empty value")
var ErrInvalidDate = errors.New("Element must contain a valid date (RFC822)")
var ErrInvalidElement = errors.New("Element must contain required sub-elements and/or attributes")
var ErrInvalidMailAddress = errors.New("Element must contain a valid mail address (RFC5322)")
var ErrInvalidURI = errors.New("Element must contain a valid URI (RFC3986)")
var ErrInvalidValue = errors.New("Element or attribute must have valid value")
var ErrNonEmptyValue = errors.New("Element must not have value")
Functions ¶
func IsValidMailAddress ¶
Whether 's' is a valid mail address (RFC5322).
func Validate ¶
func Validate(r RSSElement) (bool, []error)
In order for an RSS element (RSSElement) to be valid, it must comprise all required elements and sub-elements.
If the RSS element contains optional sub-elements with required elements, these too must be valid.
To accomplish this, we recurse through all struct fields of the struct of interface type RSSElement. If the struct field is of interface type RSSElement, the IsValid method is called. Each RSSElement is responsible for implementing its IsValid method in accordance with the RSS 2.0 Specification.
Types ¶
type Author ¶
type Author struct { XMLName xml.Name `xml:"author"` // required CharData []byte `xml:",chardata"` // required }
<author> is an optional sub-element of <item>.
Example:
<author>first.last@example.com</author>
See: https://validator.w3.org/feed/docs/rss2.html#ltauthorgtSubelementOfLtitemgt
type Category ¶
type Category struct { XMLName xml.Name `xml:"category"` // required CharData []byte `xml:",chardata"` // required Domain Domain `xml:"domain,attr,omitempty"` // optional }
<category> is an optional sub-element of <channel> and <item>.
The <channel>-level category element follows the same rules as the <item>-level category element.
See:
type Channel ¶
type Channel struct { XMLName xml.Name `xml:"channel"` // required Title Title `xml:"title"` // required Link Link `xml:"link"` // required Description Description `xml:"description"` // required Language Language `xml:"language,omitempty"` // optional Copyright Copyright `xml:"copyright,omitempty"` // optional ManagingEditor ManagingEditor `xml:"managingEditor,omitempty"` // optional WebMaster WebMaster `xml:"webMaster,omitempty"` // optional PubDate PubDate `xml:"pubDate,omitempty"` // optional LastBuildDate LastBuildDate `xml:"lastBuildDate,omitempty"` // optional Category Category `xml:"category,omitempty"` // optional Generator Generator `xml:"generator,omitempty"` // optional Docs Docs `xml:"docs,omitempty"` // optional Cloud Cloud `xml:"cloud,omitempty"` // optional TTL TTL `xml:"ttl,omitempty"` // optional Image Image `xml:"image,omitempty"` // optional Rating Rating `xml:"rating,omitempty"` // optional TextInput TextInput `xml:"textInput,omitempty"` // optional SkipHours SkipHours `xml:"skipHours,omitempty"` // optional SkipDays SkipDays `xml:"skipDays,omitempty"` // optional Item []*Item `xml:"item,omitempty"` // optional }
<channel> is a required sub-element of <rss>.
See: https://validator.w3.org/feed/docs/rss2.html#requiredChannelElements
func (Channel) IsValid ¶
Whether <channel> is valid.
In order for <channel> to be valid, it must comprise all required elements and sub-elements.
If <channel> contains optional sub-elements with required elements, these too must be valid.
To accomplish this, we recurse through all struct fields. If the struct field is of interface type RSSElement, the IsValid method is called. Each RSSElement is responsible for implementing its IsValid method in accordance with the RSS 2.0 Specification.
type Cloud ¶
type Cloud struct { XMLName xml.Name `xml:"cloud"` // required CharData []byte `xml:",chardata"` // prohibited Domain Domain `xml:"domain,attr"` // required Port Port `xml:"port,attr"` // required Path Path `xml:"path,attr"` // required RegisterProcedure RegisterProcedure `xml:"registerProcedure,attr"` // required Protocol Protocol `xml:"protocol,attr"` // required }
<cloud> is an optional sub-element of <channel>.
See: https://validator.w3.org/feed/docs/rss2.html#ltcloudgtSubelementOfLtchannelgt
type Comments ¶
type Comments struct { XMLName xml.Name `xml:"comments"` // required CharData []byte `xml:",chardata"` // required }
<comments> is an optional sub-element of <item>.
Example:
<comments>https://example.com/comments</comments>`
See: https://validator.w3.org/feed/docs/rss2.html#ltcommentsgtSubelementOfLtitemgt
type Copyright ¶
type Copyright string
<copyright> is an optional sub-element of <channel>.
See: https://validator.w3.org/feed/docs/rss2.html#optionalChannelElements
type Day ¶
type Day string
<day> is an optional sub-element of <skipDays>.
See: https://validator.w3.org/feed/docs/rss2.html#optionalChannelElements
type Description ¶
type Description struct { XMLName xml.Name `xml:"description"` // required CharData []byte `xml:",chardata"` // required }
<description> is a required sub-element of <channel> and <textInput> and an optional sub-element of <image> and <item>
See:
- https://validator.w3.org/feed/docs/rss2.html#requiredChannelElements
- https://validator.w3.org/feed/docs/rss2.html#ltimagegtSubelementOfLtchannelgt
- https://validator.w3.org/feed/docs/rss2.html#lttextinputgtSubelementOfLtchannelgt
- https://validator.w3.org/feed/docs/rss2.html#hrelementsOfLtitemgt
func (Description) IsValid ¶
func (r Description) IsValid() (bool, []error)
Returns whether <description> is valid and a slice containing any errors.
type Docs ¶
type Docs string
<docs> is an optional sub-element of <channel>.
See: https://validator.w3.org/feed/docs/rss2.html#optionalChannelElements
type Domain ¶
type Domain *string
'domain' is an optional attribute of <category> and a required attribute of <cloud>.
See:
type Enclosure ¶
type Enclosure struct { XMLName xml.Name `xml:"enclosure"` // required CharData []byte `xml:",chardata"` // prohibited URL URL `xml:"url,attr"` // required Length Length `xml:"length,attr"` // required Type Type `xml:"type,attr"` // required }
<enclosure> is an optional sub-element of <item>.
See: https://validator.w3.org/feed/docs/rss2.html#ltenclosuregtSubelementOfLtitemgt
NOTE: In most cases, the <enclosure> element is represented using a self-closing tag:
<enclosure url="..." length="..." type="..." />
From the XML specification,
>The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag.
Source: https://www.w3.org/TR/xml/#NT-ETag
Self-closing tags are currently not implemented in encoding/xml:
Ideally, both forms (a start-tag immediately followed by an end-tag, or an empty-element tag) represent valid XML, and therefore valid RSS.
type GUID ¶
type GUID struct { XMLName xml.Name `xml:"guid"` // required CharData []byte `xml:",chardata"` // required IsPermaLink *IsPermaLink `xml:"isPermaLink,attr,omitempty"` // optional }
<guid> is an optional sub-element of <item>.
Example:
<guid isPermaLink="true">https://example.com/1337</guid>
See: https://validator.w3.org/feed/docs/rss2.html#ltguidgtSubelementOfLtitemgt
type Generator ¶
type Generator string
<generator> is an optional sub-element of <channel>.
See: https://validator.w3.org/feed/docs/rss2.html#optionalChannelElements
type Height ¶
type Height string
<height> is an optional sub-element of <image>.
See: https://validator.w3.org/feed/docs/rss2.html#ltimagegtSubelementOfLtchannelgt
type Hour ¶
type Hour int
<hour> is an optional sub-element of <skipHours>.
See: https://validator.w3.org/feed/docs/rss2.html#optionalChannelElements
type Image ¶
type Image struct { XMLName xml.Name `xml:"image"` // required URL URL `xml:"url"` // required Title Title `xml:"title"` // required Link Link `xml:"link"` // required Width Width `xml:"width,omitempty"` // optional Height Height `xml:"height,omitempty"` // optional Description Description `xml:"description,omitempty"` // optional }
<image> is an optional sub-element of <channel>.
See: https://validator.w3.org/feed/docs/rss2.html#ltimagegtSubelementOfLtchannelgt
TODO: Set default values for width and height.
type IsPermaLink ¶
type IsPermaLink string
'isPermaLink' is an optional attribute of <guid>.
NOTE: Its default value is true.
See: https://validator.w3.org/feed/docs/rss2.html#ltguidgtSubelementOfLtitemgt
func (IsPermaLink) IsValid ¶
func (r IsPermaLink) IsValid() (bool, []error)
Returns whether 'isPermaLink' is valid and a slice containing any errors.
type Item ¶
type Item struct { XMLName xml.Name `xml:"item"` // required Title *Title `xml:"title,omitempty"` // conditionally required Link *Link `xml:"link,omitempty"` // optional Description *Description `xml:"description,omitempty"` // conditionally required Source *Source `xml:"source,omitempty"` // optional Enclosure *Enclosure `xml:"enclosure,omitempty"` // optional Category *Category `xml:"category,omitempty"` // optional PubDate *PubDate `xml:"pubDate,omitempty"` // optional GUID *GUID `xml:"guid,omitempty"` // optional Comments *Comments `xml:"comments,omitempty"` // optional Author *Author `xml:"author,omitempty"` // optional }
<item> is an optional sub-element of <channel>.
A channel may contain any number of <item>s.
All elements of an item are optional, however at least one of title or description must be present.
See: https://validator.w3.org/feed/docs/rss2.html#hrelementsOfLtitemgt
type Language ¶
type Language string
<language> is an optional sub-element of <channel>.
See: https://validator.w3.org/feed/docs/rss2.html#optionalChannelElements
type LastBuildDate ¶
type LastBuildDate struct { XMLName xml.Name `xml:"lastBuildDate"` // required CharData []byte `xml:",chardata"` // required }
<lastBuildDate> is an optional sub-element of <channel>.
See: https://validator.w3.org/feed/docs/rss2.html#optionalChannelElements
func (LastBuildDate) IsValid ¶
func (r LastBuildDate) IsValid() (bool, []error)
Returns whether <lastBuildDate> is valid and a slice containing any errors.
<lastBuildDate> must conform to the Date and Time Specification of RFC822, with the exception that the year may be expressed with two characters or four characters (four preferred).
type Length ¶
type Length *string
'length' is a required attribute of <enclosure>.
See: https://validator.w3.org/feed/docs/rss2.html#ltenclosuregtSubelementOfLtitemgt
type Link ¶
type Link struct { XMLName xml.Name `xml:"link"` // required CharData []byte `xml:",chardata"` // required }
<link> is a required sub-element of <channel>, <image>, <textInput>, and <item>.
See:
type ManagingEditor ¶
type ManagingEditor string
<managingEditor> is an optional sub-element of <channel>.
See: https://validator.w3.org/feed/docs/rss2.html#optionalChannelElements
func (ManagingEditor) IsValid ¶
func (r ManagingEditor) IsValid() bool
Whether <managingEditor> is valid.
type Name ¶
type Name struct { XMLName xml.Name `xml:"name"` // required CharData []byte `xml:",chardata"` // required }
<name> is a required sub-element of <textInput>.
See: https://validator.w3.org/feed/docs/rss2.html#lttextinputgtSubelementOfLtchannelgt
type Path ¶
type Path *string
'path' is required attribute of <cloud>.
See: https://validator.w3.org/feed/docs/rss2.html#ltcloudgtSubelementOfLtchannelgt
type Port ¶
type Port *string
'port' is required attribute of <cloud>.
See: https://validator.w3.org/feed/docs/rss2.html#ltcloudgtSubelementOfLtchannelgt
type Protocol ¶
type Protocol *string
'protocol' is required attribute of <cloud>.
See: https://validator.w3.org/feed/docs/rss2.html#ltcloudgtSubelementOfLtchannelgt
type PubDate ¶
type PubDate struct { XMLName xml.Name `xml:"pubDate"` // required CharData []byte `xml:",chardata"` // required }
<pubDate> is an optional sub-element of <channel> and <item>.
See:
type RSS ¶
type RSS struct { XMLName xml.Name `xml:"rss"` // required Version Version `xml:"version,attr"` // required Channel *Channel `xml:"channel"` // required }
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.
See:
type RSSElement ¶
The RSSElement interface specifies a single method, IsValid. IsValid checks whether the element conforms to the RSS 2.0 Specification.
type Rating ¶
type Rating string
<rating> is an optional sub-element of <channel>.
See: https://validator.w3.org/feed/docs/rss2.html#optionalChannelElements
type RegisterProcedure ¶
type RegisterProcedure *string
'registerProcedure' is required attribute of <cloud>.
See: https://validator.w3.org/feed/docs/rss2.html#ltcloudgtSubelementOfLtchannelgt
type SkipDays ¶
type SkipDays struct { XMLName xml.Name `xml:"skipDays"` // required Day []*Day `xml:"hour"` // required }
<skipDays> is an optional sub-element of <channel>.
See: https://validator.w3.org/feed/docs/rss2.html#optionalChannelElements
type SkipHours ¶
type SkipHours struct { XMLName xml.Name `xml:"skipHours"` // required Hour []*Hour `xml:"hour"` // required }
<skipHours> is an optional sub-element of <channel>.
See: https://validator.w3.org/feed/docs/rss2.html#optionalChannelElements
type Source ¶
type Source struct { XMLName xml.Name `xml:"source"` // required CharData []byte `xml:",chardata"` // optional URL URL `xml:"url,attr"` // required }
<source> is an optional sub-element of <item>.
See: https://validator.w3.org/feed/docs/rss2.html#ltsourcegtSubelementOfLtitemgt
type TTL ¶
type TTL struct { XMLName xml.Name `xml:"ttl"` // required CharData []byte `xml:",chardata"` // required }
<ttl> is an optional sub-element of <channel>.
See: https://validator.w3.org/feed/docs/rss2.html#ltttlgtSubelementOfLtchannelgt
type TextInput ¶
type TextInput struct { XMLName xml.Name `xml:"textInput"` // required Title *Title `xml:"title"` // required Description *Description `xml:"description"` // required Name *Name `xml:"name"` // required Link *Link `xml:"link"` // required }
<textInput> is an optional sub-element of <channel>.
See: https://validator.w3.org/feed/docs/rss2.html#lttextinputgtSubelementOfLtchannelgt
type Title ¶
type Title struct { XMLName xml.Name `xml:"title"` // required CharData []byte `xml:",chardata"` // required }
<title> is a required sub-element of <channel>, <textInput>, and <item>.
See:
type Type ¶
type Type *string
'type' is a required attribute of <enclosure>.
See: https://validator.w3.org/feed/docs/rss2.html#ltenclosuregtSubelementOfLtitemgt
type URL ¶
type URL *string
<url> is a required sub-element of <image>.
It is also a required attribute of <source> and <enclosure>.
See:
type WebMaster ¶
type WebMaster string
<webMaster> is an optional sub-element of <channel>.
See: https://validator.w3.org/feed/docs/rss2.html#optionalChannelElements