rss

package module
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2019 License: MIT Imports: 9 Imported by: 0

README

Simple RSS package

A very simple RSS package for reading RSS Feeds.

    const url = "https://polisen.se/aktuellt/rss/skane/handelser-rss---skane/"

    res, err := http.Get(url)
    if err != nil {
        return
    }
    defer res.Body.Close()

    feed, _ := rss.NewFeed(res.Body)

    fmt.Println(feed.Channel.Title)

    for _, itm := range feed.Channel.Items {
        fmt.Println(itm)
    }

Documentation

Overview

Package rss provides functions to parse RSS 2.0 feeds.

Index

Constants

This section is empty.

Variables

View Source
var CommonDateLayouts = []string{time.RFC1123, time.RFC1123Z, time.RFC3339}

CommonDateLayouts is an array of commonly used date formats

Functions

func FilterItems added in v1.1.0

func FilterItems(in <-chan Item, fn func(Item) bool) chan Item

FilterItems filters items through fn

func MuxSources added in v1.2.1

func MuxSources(sources ...string) chan Item

MuxSources muxes

func WriteAsJSON added in v1.2.1

func WriteAsJSON(w io.Writer, in <-chan Item) (err error)

WriteAsJSON writes Items as JSON array to w

Types

type Channel

type Channel struct {
	Items       []Item `xml:"item"`
	Description string `xml:"description"`
	Title       string `xml:"title"`
	Link        string `xml:"link"`
	PubDate     string `xml:"pubDate"`
	Language    string `xml:"language"`
	Copyright   string `xml:"copyright"`
}

Channel is an RSS 2.0 Channel

type DateSorter added in v1.1.0

type DateSorter []Item

DateSorter sorts a list of items by date

func (DateSorter) Len added in v1.1.0

func (s DateSorter) Len() int

func (DateSorter) Less added in v1.1.0

func (s DateSorter) Less(i, j int) bool

func (DateSorter) Swap added in v1.1.0

func (s DateSorter) Swap(i, j int)

type Enclosure

type Enclosure struct {
	URL  string `xml:"url,attr" json:"URL"`
	Type string `xml:"type,attr" json:"Type,omitempty"`
}

Enclosure is an RSS 2.0 Enclosure

type Feed

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

Feed is the RSS 2.0 root

func NewFeed

func NewFeed(r io.Reader) (f *Feed, err error)

NewFeed creates a new Feed from r

type Item

type Item struct {
	PubDate     PubDate      `xml:"pubDate" json:"PubDate"`
	Description string       `xml:"description" json:"Description"`
	GUID        string       `xml:"guid" json:"GUID"`
	Link        string       `xml:"link" json:"Link"`
	Creator     string       `xml:"creator" json:"Creator"`
	Category    []string     `xml:"category" json:"Category"`
	Content     MediaContent `xml:"content" json:"Content"`
	Enclosure   Enclosure    `xml:"enclosure" json:"Enclosure"`
	Title       string       `xml:"title" json:"Title"`
	Source      Source       `xml:"source" json:"Source"`
}

Item is an RSS 2.0 Item

type MediaContent

type MediaContent struct {
	URL    string `xml:"url,attr" json:"URL,omitempty"`
	Width  string `xml:"width,attr" json:"Width,omitempty"`
	Height string `xml:"height,attr" json:"Height,omitempty"`
	Medium string `xml:"medium,attr" json:"Medium,omitempty"`
}

MediaContent is the Yahoo Media RSS

type PubDate added in v1.2.2

type PubDate struct {
	T time.Time
}

func (PubDate) MarshalJSON added in v1.2.2

func (p PubDate) MarshalJSON() ([]byte, error)

MarshalJSON marshals RSS Pubdate to JSON

func (*PubDate) UnmarshalXML added in v1.2.2

func (p *PubDate) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals RSS dates

type Source added in v1.1.0

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

Source is the RSS channel that the item came from.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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