atom

package
v4.24.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2017 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package atom of the Tideland Go Library implements an atom feed client.

The Atom package provides the Atom XML schema as Go types for the usage with the standard marshalling/unmarshalling. The supported format is Atom 1.0. A client allows to retrieve Atom documents.

Index

Constants

View Source
const (
	Version = "1.0"
	XMLNS   = "http://www.w3.org/2005/Atom"

	TextType  = "text"
	HTMLType  = "html"
	XHTMLType = "xhtml"

	AlternateRel = "alternate"
	EnclosureRel = "enclosure"
	RelatedRel   = "related"
	SelfRel      = "self"
	ViaRel       = "via"
)

Attributes of Atom XML documents.

View Source
const (
	ErrValidation = iota + 1
	ErrParsing
	ErrNoPlainText
)

Error codes of the atom feed package.

Variables

This section is empty.

Functions

func ComposeTime

func ComposeTime(t time.Time) string

ComposeTime takes a Go time and converts it into a valid Atom time string.

func Encode

func Encode(w io.Writer, feed *Feed) error

Encode writes the feed to the writer.

func IsNoPlainTextError

func IsNoPlainTextError(err error) bool

IsNoPlainTextError checks if the error signals no plain content inside a text element.

func IsParsingError

func IsParsingError(err error) bool

IsParsingError checks if the error signals a bad formatted value.

func IsValidationError

func IsValidationError(err error) bool

IsValidationError checks if the error signals an invalid feed.

func ParseTime

func ParseTime(s string) (t time.Time, err error)

ParseTime analyzes the Atom date/time string and returns it as Go time.

Types

type Author

type Author struct {
	Name  string `xml:"name"`
	URI   string `xml:"uri,omitempty"`
	EMail string `xml:"email,omitempty"`
}

Author names the author of the feed.

func (*Author) Validate

func (a *Author) Validate() error

Validate checks if a feed author is valid.

type Category

type Category struct {
	Term   string `xml:"term,attr"`
	Scheme string `xml:"scheme,attr,omitempty"`
	Label  string `xml:"label,attr,omitempty"`
}

Category specifies a category that the feed belongs to.

func (*Category) Validate

func (c *Category) Validate() error

Validate checks if a feed category is valid.

type Contributor

type Contributor struct {
	Name string `xml:"name"`
}

Contributor names one contributor of the feed.

func (*Contributor) Validate

func (c *Contributor) Validate() error

Validate checks if a feed contributor is valid.

type Entry

type Entry struct {
	Id           string         `xml:"id"`
	Title        *Text          `xml:"title"`
	Updated      string         `xml:"updated"`
	Authors      []*Author      `xml:"author,omitempty"`
	Content      *Text          `xml:"content,omitempty"`
	Link         *Link          `xml:"link,omitempty"`
	Summary      *Text          `xml:"subtitle,omitempty"`
	Categories   []*Category    `xml:"category,omitempty"`
	Contributors []*Contributor `xml:"contributor,omitempty"`
	Published    string         `xml:"published,omitempty"`
	Source       *Source        `xml:"source,omitempty"`
	Rights       *Text          `xml:"rights,omitempty"`
}

Entry defines one feed entry.

func (*Entry) Validate

func (e *Entry) Validate() error

Validate checks if the feed entry is valid.

type Feed

type Feed struct {
	XMLName      string         `xml:"feed"`
	XMLNS        string         `xml:"xmlns,attr"`
	Id           string         `xml:"id"`
	Title        *Text          `xml:"title"`
	Updated      string         `xml:"updated"`
	Authors      []*Author      `xml:"author,omitempty"`
	Link         *Link          `xml:"link,omitempty"`
	Categories   []*Category    `xml:"category,omitempty"`
	Contributors []*Contributor `xml:"contributor,omitempty"`
	Generator    *Generator     `xml:"generator,omitempty"`
	Icon         string         `xml:"icon,omitempty"`
	Rights       *Text          `xml:"rights,omitempty"`
	Subtitle     *Text          `xml:"subtitle,omitempty"`
	Entries      []*Entry       `xml:"entry"`
}

Feed is the root element of the document.

func Decode

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

Decode reads the feed from the reader.

func Get

func Get(u *url.URL) (*Feed, error)

Get retrieves a feed from the given URL.

func (*Feed) Validate

func (f *Feed) Validate() error

Validate checks if the feed is valid.

type Generator

type Generator struct {
	Generator string `xml:",chardata"`
	URI       string `xml:"uri,attr,omitempty"`
	Version   string `xml:"version,attr,omitempty"`
}

Generator identifies the software used to generate the feed, for debugging and other purposes.

func (*Generator) Validate

func (g *Generator) Validate() error

Validate checks if a feed generator is valid.

type Link struct {
	HRef     string `xml:"href,attr"`
	Rel      string `xml:"rel,attr,omitempty"`
	Type     string `xml:"type,attr,omitempty"`
	HRefLang string `xml:"hreflang,attr,omitempty"`
	Title    string `xml:"title,attr,omitempty"`
	Length   int    `xml:"length,attr,omitempty"`
}

Link identifies a related web page.

func (*Link) Validate

func (l *Link) Validate() error

Validate checks if the feed link is valid.

type Source

type Source struct {
	Authors      []*Author      `xml:"author,omitempty"`
	Categories   []*Category    `xml:"category,omitempty"`
	Contributors []*Contributor `xml:"contributor,omitempty"`
	Generator    *Generator     `xml:"generator,omitempty"`
	Icon         string         `xml:"icon,omitempty"`
	Id           string         `xml:"id,omitempty"`
	Link         *Link          `xml:"link,omitempty"`
	Rights       *Text          `xml:"rights,omitempty"`
	Subtitle     *Text          `xml:"subtitle,omitempty"`
	Title        *Text          `xml:"title,omitempty"`
	Updated      string         `xml:"updated,omitempty"`
}

Source preserves the source feeds metadata if the entry is copied from one feed into another feed.

func (*Source) Validate

func (s *Source) Validate() error

Validate checks if a feed entry source is valid.

type Text

type Text struct {
	Text string `xml:",chardata"`
	Src  string `xml:"src,attr,omitempty"`
	Type string `xml:"type,attr,omitempty"`
}

Text contains human-readable text, usually in small quantities. The type attribute determines how this information is encoded.

func (Text) PlainText

func (t Text) PlainText() (string, error)

PlainText returns the text as string without any markup. Content from external sources will be retrieved.

Jump to

Keyboard shortcuts

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