Documentation
¶
Overview ¶
Package rssfeed fetches and parses RSS 2.0 and Atom feeds for the dashboard news tray. It uses encoding/xml only: the feeds it reads are small, and the subset of either format the tray renders (title, link, summary, date, id) is narrow enough that a full feed library would be dead weight.
Index ¶
Constants ¶
const ( // DefaultTTL is how long a fetched feed is served from cache. DefaultTTL = 15 * time.Minute )
const (
// MaxItemsPerFeed caps what one feed contributes to the tray.
MaxItemsPerFeed = 20
)
Variables ¶
var ErrFeedTooLarge = errors.New("feed exceeds the 2 MB size limit")
ErrFeedTooLarge is returned when a feed body exceeds maxFeedBytes.
var ErrNotAFeed = errors.New("document is not an RSS or Atom feed")
ErrNotAFeed is returned when the document parses as XML but is neither an RSS nor an Atom feed (for example an HTML page served at the feed URL).
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item struct {
GUID string `json:"guid"`
Title string `json:"title"`
Link string `json:"link"`
Summary string `json:"summary,omitempty"`
PublishedAt time.Time `json:"published_at"`
}
Item is one normalized entry from a feed.
func Parse ¶
Parse decodes an RSS 2.0, RSS 1.0 or Atom document into at most MaxItemsPerFeed items, newest first. Entries without a title and a link are dropped, since the tray can neither label nor open them.
func ParseHTMLPage ¶
ParseHTMLPage extracts entries from a news listing page that publishes no feed (anthropic.com/news is the motivating case). An entry is an <a href> that wraps either a heading, or a <time> plus an element whose class names a title (the compact list rows such pages use). The heading or title element is the title, a <time> inside the card is the date (its datetime attribute, else its text), and the first <p> is the summary. Relative links resolve against base. Links that leave base's host are ignored, as are duplicates.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager fetches feeds through an SSRF-safe client and caches the parsed result per URL. Memory retained is bounded by the number of distinct URLs fetched (at most MaxItemsPerFeed items each); Forget drops a URL's entry when its feed is deleted or repointed.
func NewManager ¶
func NewManager() *Manager
NewManager returns a Manager that refuses private and link-local targets, both at validation time and at dial time (defeating DNS rebinding).
func NewManagerWithClient ¶
NewManagerWithClient is the test seam: it uses the given client and skips URL validation, so feeds can be served from an httptest server on loopback.
func (*Manager) Fetch ¶
Fetch downloads and parses url without touching the cache. Used directly to validate a feed before it is saved.