Documentation
¶
Overview ¶
Package feed provides the types and methods to manage feeds in the application using an all-in-memory approach.
Index ¶
- Constants
- func ParseParams(params any, dst FeedParams) error
- func UID(input string) string
- type Feed
- func (f *Feed) MarkAllRead(before int64)
- func (f *Feed) Prune(n int, observedRawItems int)
- func (f *Feed) Refresh(items []RawItem, ts int64, fetchErr error)
- func (f *Feed) SortedItems() []Item
- func (f *Feed) Summary(withItems bool, itemMapper map[string]*Feed) *FeedSummary
- func (f *Feed) UID() string
- type FeedParams
- type FeedSummary
- type Item
- type ItemSummary
- type RawItem
Constants ¶
const ( TypeXML = "xml" TypeHTML = "html" TypeImage = "img" )
Variables ¶
This section is empty.
Functions ¶
func ParseParams ¶
func ParseParams(params any, dst FeedParams) error
parseParams takes feed params, unmarshalls them into the dst struct and validates them.
Types ¶
type Feed ¶
type Feed struct { // Name is the name of the feed as defined by the user. Name string `json:"name"` // Type is the type of the feed. It can be one of the types defined in this // file. Type string `json:"type"` // URL is the URL from which the feed is fetched. If this is empty, the // feed is assumed to be a virtual feed managed by the application. URL string `json:"url"` // Items is a map of items in the feed. The key is the UID of the item. Items map[string]*Item `json:"items"` // Params is an object with parameters that are specific to the feed type. // It is up to the feed type to define what these parameters are, and they // are usually used when parsing or refreshing the feed. Params any `json:"params"` // LastRefreshedAt is the time when the feed was last fetched. LastRefreshedAt int64 `json:"updated_at"` // LastRefreshError is the last error that occurred when refreshing the // feed. LastRefreshError string `json:"error"` }
Feed represents a feed in the application.
func (*Feed) MarkAllRead ¶
MarkAllRead marks all feed items as read if their timestamp is less than or equal to the given before timestamp.
func (*Feed) Prune ¶
Prune removes items from the feed until the number of items is less than or equal to n. It removes the last items as determined by Feed.SortedItems. If n is less than zero, or if the feeds has less than n items, it does nothing. If n is zero and observedRawItems is greater than zero, it takes into account observedRawItems, trying to reach a balance between a minimum of 100 items and a maximum of 200 items. If the feed's max_items param is set, it is always respected as long as it is greater than zero.
func (*Feed) Refresh ¶
Refresh updates the feed with information coming from raw items or an error coming from a fetcher, and then prunes the feed to the maximum number of items.
func (*Feed) SortedItems ¶
SortedItems returns the items in the feed sorted by timestamp, position and then URL in descending order.
func (*Feed) Summary ¶
func (f *Feed) Summary(withItems bool, itemMapper map[string]*Feed) *FeedSummary
Summary returns a summary of the feed. If withItems is true, it includes the items in the feed. itemMapper should usually be nil; it's only used in special cases when building virtual feeds containing items from other feeds.
type FeedParams ¶
type FeedParams interface {
Validate() error
}
feedParams is to be implemented by specific feed params structs.
type FeedSummary ¶
type FeedSummary struct { // UID is the unique identifier of the feed. UID string `json:"uid"` // URL is the URL from which the feed is fetched. URL string `json:"url"` // Name is the name of the feed as defined by the user. Name string `json:"name"` // Items is a list of items in the feed. It is usually empty, unless // explicitly requested. Items []*ItemSummary `json:"items,omitempty"` // LastUpdated is the time when the feed was last fetched. LastUpdated int64 `json:"last_updated"` // LastError is the last error that occurred when refreshing the feed. LastError string `json:"last_error"` // ItemCount is the number of items in the feed. ItemCount int `json:"item_count"` // ReadCount is the number of items in the feed that were marked as read. ReadCount int `json:"read_count"` }
FeedSummary is the external representation of the feed (e.g., for presenting to users).
type Item ¶
type Item struct { RawItem // FeedUID is the UID of the feed that this item belongs to. This field is // populated by the feed itself. FeedUID string `json:"feed_uid"` // Timestamp is the time when the item was first seen. This field is // populated by the feed itself. Timestamp int64 `json:"timestamp"` // Read is true if the item was marked as read by the user. Read bool `json:"read"` }
Item is the representation of an item in the application, with additional fields that are not present in the raw item.
type ItemSummary ¶
type ItemSummary struct { // UID is the unique identifier of the item. UID string `json:"uid"` // FeedUID is the UID of the feed that this item belongs to. FeedUID string `json:"feed_uid"` // FeedName is the name of the feed that this item belongs to. FeedName string `json:"feed_name"` // URL is the URL of the item. It comes directly from the feed and is not // sanitized. Do not embed it in the page directly without proper measures. URL string `json:"url"` // Title is a short title or description of the item. It comes directly // from the feed and is not sanitized. Do not embed it in the page directly // without proper measures. Title string `json:"title"` // Timestamp is the time when the item was first seen. Timestamp int64 `json:"timestamp"` // Authors is a short comma-separated summary of authors of the item. It // comes directly from the feed and is not sanitized. Do not embed it in // the page directly without proper measures. Authors string `json:"authors"` // Read is true if the item was marked as read by the user. Read bool `json:"read"` // Content is the full content of the item, usually a sanitized HTML // fragment. It comes directly from the feed and may safely be embedded in // the page directly. Content string `json:"content,omitempty"` }
ItemSummary is the external representation of the item (e.g., for presenting to users).
type RawItem ¶
type RawItem struct { // URL is the URL of the item. URL string `json:"url"` // Title is a short title or description of the item. Title string `json:"title"` // Authors is short summary of authors of the item (usually // comma-separated). Authors string `json:"authors"` // Content is the full content of the item, usually a sanitized HTML // fragment. Content string `json:"content"` // Position is the position of the item in the feed when it was first seen. // Assuming two items are first seen at the same time, a lower position // typically means a newer item (i.e., that's how blogs are typically laid // out). Position int `json:"position"` }
RawItem is the representation of an item as it comes from a feed.