feed

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Construct

func Construct(s *state.State, logger *slog.Logger) (string, error)

func ToXML

func ToXML(feed XmlFeed) (string, error)

turn a feed object (either a Feed, AtomFeed, or RssFeed) into xml returns an error if xml marshaling fails

func Write

func Write(s *state.State, atom string) error

func WriteXML

func WriteXML(feed XmlFeed, w io.Writer) error

WriteXML writes a feed object (either a Feed, AtomFeed, or RssFeed) as XML into the writer. Returns an error if XML marshaling fails.

Types

type Atom

type Atom struct {
	*Feed
}

func (*Atom) AtomFeed

func (a *Atom) AtomFeed() *AtomFeed

create a new AtomFeed with a generic Feed struct's data

func (*Atom) FeedXml

func (a *Atom) FeedXml() interface{}

FeedXml returns an XML-Ready object for an Atom object

type AtomAuthor

type AtomAuthor struct {
	XMLName xml.Name `xml:"author"`
	AtomPerson
}

type AtomCategories

type AtomCategories []string

type AtomContent

type AtomContent struct {
	XMLName xml.Name `xml:"content"`
	Content string   `xml:",chardata"`
	Type    string   `xml:"type,attr"`
}

type AtomContributor

type AtomContributor struct {
	XMLName xml.Name `xml:"contributor"`
	AtomPerson
}

type AtomEntry

type AtomEntry struct {
	Content     *AtomContent
	Author      *AtomAuthor
	Summary     *AtomSummary
	Contributor *AtomContributor
	XMLName     xml.Name `xml:"entry"`
	Updated     string   `xml:"updated"`
	Rights      string   `xml:"rights,omitempty"`
	Source      string   `xml:"source,omitempty"`
	Published   string   `xml:"published,omitempty"`
	Id          string   `xml:"id"`
	Title       string   `xml:"title"`
	Xmlns       string   `xml:"xmlns,attr,omitempty"`
	Links       []AtomLink
	Categories  AtomCategories `xml:"category,omitempty"`
}

type AtomFeed

type AtomFeed struct {
	XMLName     xml.Name `xml:"feed"`
	Xmlns       string   `xml:"xmlns,attr"`
	Title       string   `xml:"title"`   // required
	Id          string   `xml:"id"`      // required
	Updated     string   `xml:"updated"` // required
	Icon        string   `xml:"icon,omitempty"`
	Rights      string   `xml:"rights,omitempty"` // copyright used
	Subtitle    string   `xml:"subtitle,omitempty"`
	Link        *AtomLink
	Author      *AtomAuthor `xml:"author,omitempty"`
	Contributor *AtomContributor
	Entries     []*AtomEntry `xml:"entry"`
}

func (*AtomFeed) FeedXml

func (a *AtomFeed) FeedXml() interface{}

FeedXml returns an XML-ready object for an AtomFeed object

type AtomLink struct {
	// Atom 1.0 <link rel="enclosure" type="audio/mpeg" title="MP3" href="http://www.example.org/myaudiofile.mp3" length="1234" />
	XMLName xml.Name `xml:"link"`
	Href    string   `xml:"href,attr"`
	Rel     string   `xml:"rel,attr,omitempty"`
	Type    string   `xml:"type,attr,omitempty"`
	Length  string   `xml:"length,attr,omitempty"`
}

Multiple links with different rel can coexist

type AtomPerson

type AtomPerson struct {
	Name  string `xml:"name,omitempty"`
	Uri   string `xml:"uri,omitempty"`
	Email string `xml:"email,omitempty"`
}

type AtomSummary

type AtomSummary struct {
	XMLName xml.Name `xml:"summary"`
	Content string   `xml:",chardata"`
	Type    string   `xml:"type,attr"`
}

type Author

type Author struct {
	Name, Email string
}

type Enclosure

type Enclosure struct {
	Url, Length, Type string
}

type Feed

type Feed struct {
	Updated     time.Time
	Created     time.Time
	Link        *Link
	Author      *Author
	Image       *Image
	Title       string
	Description string
	Id          string
	Subtitle    string
	Copyright   string
	Items       []*Item
}

func (*Feed) Add

func (f *Feed) Add(item *Item)

add a new Item to a Feed

func (*Feed) Sort

func (f *Feed) Sort(less func(a, b *Item) bool)

Sort sorts the Items in the feed with the given less function.

func (*Feed) ToAtom

func (f *Feed) ToAtom() (string, error)

// creates an Atom representation of this feed

func (*Feed) WriteAtom

func (f *Feed) WriteAtom(w io.Writer) error

WriteAtom writes an Atom representation of this feed to the writer.

type Image

type Image struct {
	Url, Title, Link string
	Width, Height    int
}

type Item

type Item struct {
	Link        *Link
	Source      *Link
	Author      *Author
	Enclosure   *Enclosure
	Title       string
	Description string // used as description in rss, summary in atom
	Id          string // used as guid in rss, id in atom
	Updated     time.Time
	Created     time.Time
	Content     string
	Categories  []string
}
type Link struct {
	Href, Rel, Type, Length string
}

type UUID

type UUID [16]byte

func NewUUID

func NewUUID() *UUID

create a new uuid v4

func (*UUID) String

func (u *UUID) String() string

type XmlFeed

type XmlFeed interface {
	FeedXml() interface{}
}

interface used by ToXML to get a object suitable for exporting XML.

Jump to

Keyboard shortcuts

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