feed

package
v1.0.18 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fetch

func Fetch(targetURL string) (io.ReadCloser, error)

Fetch is the simple HTTP helper used for article text fetching.

func FetchArticleText

func FetchArticleText(articleURL string) (string, error)

func SetMaxFeedBodyBytes

func SetMaxFeedBodyBytes(limit int)

Types

type ErrNeedRedirect

type ErrNeedRedirect struct{ URL string }

ErrNeedRedirect signals that feed auto-discovery found a better URL.

func (*ErrNeedRedirect) Error

func (e *ErrNeedRedirect) Error() string

type FetchErrorKind

type FetchErrorKind int

FetchErrorKind classifies the outcome of a FetchFeed call.

const (
	KindSuccess               FetchErrorKind = iota
	KindNetworkError                         // DNS failure, connection refused, etc.
	KindTimeout                              // deadline exceeded
	KindTooManyRedirects                     // more than maxRedirects hops
	KindRedirectLoop                         // same URL appeared twice in the chain
	KindHttpError                            // non-2xx final status code
	KindHtmlInsteadOfFeed                    // 200 HTML page, no feed auto-discovered
	KindBotProtectionDetected                // JS challenge, captcha, Cloudflare wall
	KindFeedTooLarge                         // body exceeds maxFeedBodyBytes
	KindInvalidFeedFormat                    // body is neither HTML nor valid feed XML
	KindParseError                           // gofeed parse failure
)

type FetchResult

type FetchResult struct {
	Kind          FetchErrorKind
	OriginalURL   string
	RedirectChain []string // every URL visited, including OriginalURL; len >= 1
	FinalURL      string
	StatusCode    int // 0 when no HTTP response was received (e.g. network error)
	ContentType   string
	Snippet       string // up to snippetLen bytes of the response body
	Err           error
	Feed          *ParsedFeed // non-nil only on KindSuccess

	// SuggestURLUpdate is true when a 301/308 permanent redirect was followed and
	// the final URL differs from the original — the caller can update the stored URL.
	SuggestURLUpdate bool
	SuggestedURL     string
}

FetchResult is the full outcome of a FetchFeed call.

func FetchFeed

func FetchFeed(originalURL string) *FetchResult

FetchFeed performs a robust fetch of the feed at originalURL. It follows redirects manually (up to maxRedirects), detects loops, preserves method semantics on 307/308, and classifies all error kinds.

func (*FetchResult) FriendlyMessage

func (r *FetchResult) FriendlyMessage() string

FriendlyMessage returns a short human-readable description of the result. Returns an empty string on success.

func (*FetchResult) HasDetails

func (r *FetchResult) HasDetails() bool

HasDetails reports whether the result carries diagnostic info worth showing in a details view (status code, content-type, URL chain, snippet).

func (*FetchResult) IsSuccess

func (r *FetchResult) IsSuccess() bool

IsSuccess reports whether the fetch produced a parsed feed.

type ParsedFeed

type ParsedFeed struct {
	Title       string
	Description string
	FaviconURL  string
	Items       []ParsedItem
}

func FetchAndParse

func FetchAndParse(feedURL string) (*ParsedFeed, string, error)

FetchAndParse is the legacy interface backed by FetchFeed.

func Parse

func Parse(r io.Reader) (*ParsedFeed, error)

Parse reads an RSS/Atom/JSON feed from r. If the content looks like HTML it attempts feed auto-discovery, returning the discovered feed URL as a sentinel error so the caller can retry with that URL.

type ParsedItem

type ParsedItem struct {
	GUID        string
	Title       string
	Link        string
	Content     string // raw HTML
	PublishedAt time.Time
}

Jump to

Keyboard shortcuts

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