Help us shape the future of Go! Take the 2026 Go Developer Survey

feed

package
v0.37.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package feed fetches the bentoo notices feed over HTTPS with ETag revalidation, a body size cap and a request deadline. It is a library package: it returns errors carrying the URL, the status and the byte count, and leaves logging to its caller.

Index

Constants

View Source
const (
	// MaxBodyBytes is the largest feed body accepted.
	MaxBodyBytes int64 = 1 << 20

	// Timeout bounds a whole fetch made with the default client.
	Timeout = 30 * time.Second
)

Variables

View Source
var (
	// ErrInsecureURL is returned by New for a feed URL that is not https.
	ErrInsecureURL = errors.New("feed URL is not https")

	// ErrTooLarge is returned by Fetch when the body exceeds MaxBodyBytes.
	ErrTooLarge = errors.New("feed body exceeds 1 MiB")
)

Functions

func DefaultClient

func DefaultClient() *http.Client

DefaultClient returns the client New uses when given none.

func DefaultUserAgent

func DefaultUserAgent() string

DefaultUserAgent returns "bentoo-tray/<tray version>", the version the tray reports for itself rather than the bentoolkit release it ships in.

Types

type Fetcher

type Fetcher struct {
	// contains filtered or unexported fields
}

Fetcher performs conditional GETs of one feed URL.

func New

func New(rawURL string, client *http.Client, userAgent string) (*Fetcher, error)

New returns a Fetcher for rawURL. A URL that is not an absolute https URL with a host is refused with ErrInsecureURL naming it. A nil client is replaced by the default: a 30 s timeout, the shared transport and the credential-safe redirect policy. An empty userAgent is replaced by "bentoo-tray/<version>".

func (*Fetcher) Fetch

func (f *Fetcher) Fetch(ctx context.Context, etag string) (Result, error)

Fetch GETs the feed, sending etag as If-None-Match when it is not empty. A 304 yields a Result with NotModified set and no feed; a 200 yields the parsed feed and the response's ETag. Any other status is a *StatusError; a body past MaxBodyBytes is ErrTooLarge; a 200 whose body is not a valid feed is an error wrapping notices.ErrInvalidFeed. Every error names the URL, and every response, failed or not, reports Status and Bytes.

type Result

type Result struct {
	NotModified bool
	ETag        string
	Feed        notices.Feed
	Status      int
	Bytes       int64
}

Result is the outcome of a fetch that received a response. Status and Bytes are set whenever a response arrived, including alongside an error, so the caller can log them on every outcome.

type StatusError

type StatusError struct {
	Status     int
	RetryAfter time.Duration
	Bytes      int64
}

StatusError reports a response whose status is neither 200 nor 304. Bytes is the size of the body read, and RetryAfter the server's Retry-After header as a duration (zero when absent, unparsable or in the past).

func (*StatusError) Error

func (e *StatusError) Error() string

Jump to

Keyboard shortcuts

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